Linux命令(86)之touch

简介: Linux命令(86)之touch

linux命令之touch

1.touch介绍
linux命令touch是用来创建普通文件,若文件存在,则只修改当前文件的时间

2.touch用法
touch [参数] FileName

touch参数
参数 说明
-r 使用参照文档的时间记录
-d 设置日期与时间,可以使用不同的时间格式
3.实例
3.1.创建ztj.txt文件
命令:

touch ztj.txt

[root@centos79-3 ~]# touch ztj.txt
[root@centos79-3 ~]# ls -l ztj.txt
-rw-r--r-- 1 root root 0 Sep 13 09:16 ztj.txt
[root@centos79-3 ~]#
3.2.参照/etc/passwd文件的时间记录,创建aa.txt
命令:

touch -r /etc/passwd aa.txt

[root@centos79-3 ~]# touch -r /etc/passwd aa.txt
[root@centos79-3 ~]# ls -l aa.txt
-rw-r--r-- 1 root root 0 Sep 8 20:03 aa.txt
[root@centos79-3 ~]# ls -l /etc/passwd
-rw-r--r-- 1 root root 835 Sep 8 20:03 /etc/passwd
[root@centos79-3 ~]#
3.3.把*.sh脚本时间更改为2023/9/11
命令:

touch -d "9/11/2023" *.sh

[root@centos79-3 ~]# touch -d "9/11/2023" .sh
[root@centos79-3 ~]# ls -l
.sh
-rwxr-xr-x 1 root root 3109 Sep 11 00:00 basic_init.sh
-rwxr-xr-x 1 root root 84 Sep 11 00:00 check_nginx.sh
-rwxr-xr-x 1 root root 22 Sep 11 00:00 date.sh
[root@centos79-3 ~]#
3.4.同时创建多个文件
命令:

touch {1..10}.txt

[root@centos79-3 ~]# touch {1..10}.txt
[root@centos79-3 ~]# ls -l *.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 10.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 1.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 2.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 3.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 4.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 5.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 6.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 7.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 8.txt
-rw-r--r-- 1 root root 0 Sep 13 09:20 9.txt

————————————————
版权声明:本文为CSDN博主「小黑要上天」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z19861216/article/details/132845101

目录
相关文章
|
17天前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
54 23
Linux系统之whereis命令的基本使用
|
3月前
|
Linux 网络安全 数据安全/隐私保护
Linux 超级强大的十六进制 dump 工具:XXD 命令,我教你应该如何使用!
在 Linux 系统中,xxd 命令是一个强大的十六进制 dump 工具,可以将文件或数据以十六进制和 ASCII 字符形式显示,帮助用户深入了解和分析数据。本文详细介绍了 xxd 命令的基本用法、高级功能及实际应用案例,包括查看文件内容、指定输出格式、写入文件、数据比较、数据提取、数据转换和数据加密解密等。通过掌握这些技巧,用户可以更高效地处理各种数据问题。
381 8
|
3月前
|
监控 Linux
如何检查 Linux 内存使用量是否耗尽?这 5 个命令堪称绝了!
本文介绍了在Linux系统中检查内存使用情况的5个常用命令:`free`、`top`、`vmstat`、`pidstat` 和 `/proc/meminfo` 文件,帮助用户准确监控内存状态,确保系统稳定运行。
1193 6
|
3月前
|
Linux
在 Linux 系统中,“cd”命令用于切换当前工作目录
在 Linux 系统中,“cd”命令用于切换当前工作目录。本文详细介绍了“cd”命令的基本用法和常见技巧,包括使用“.”、“..”、“~”、绝对路径和相对路径,以及快速切换到上一次工作目录等。此外,还探讨了高级技巧,如使用通配符、结合其他命令、在脚本中使用,以及实际应用案例,帮助读者提高工作效率。
224 3
|
3月前
|
监控 安全 Linux
在 Linux 系统中,网络管理是重要任务。本文介绍了常用的网络命令及其适用场景
在 Linux 系统中,网络管理是重要任务。本文介绍了常用的网络命令及其适用场景,包括 ping(测试连通性)、traceroute(跟踪路由路径)、netstat(显示网络连接信息)、nmap(网络扫描)、ifconfig 和 ip(网络接口配置)。掌握这些命令有助于高效诊断和解决网络问题,保障网络稳定运行。
152 2
|
4天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
51 25
|
2天前
|
缓存 Linux
Linux查看内存命令
1. free free命令是最常用的查看内存使用情况的命令。它显示系统的总内存、已使用内存、空闲内存和交换内存的总量。 free -h • -h 选项:以易读的格式(如GB、MB)显示内存大小。 输出示例: total used free shared buff/cache available Mem: 15Gi 4.7Gi 4.1Gi 288Mi 6.6Gi 9.9Gi Swap: 2.0Gi 0B 2.0Gi • to
14 2
|
30天前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
41 11
|
2月前
|
Linux Shell
Linux 10 个“who”命令示例
Linux 10 个“who”命令示例
117 14
Linux 10 个“who”命令示例
|
2月前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
239 20