touch命令的功能是用于创建空文件与修改时间戳。如果文件不存在,则会创建出一个空内容的文本文件;如果文件已经存在,则会对文件的Atime(访问时间)和Ctime(修改时间)进行修改操作,管理员可以完成此项工作,而普通用户只能管理主机的文件。
目录
3.2 在当前工作目录中,创建有序的10个文件并以 txt 为后缀
一、语法格式
touch [参数] 文件
二、常用参数
-d | 设定时间与日期,可以使用各种不同的格式 |
三、命令实战
3.1 在当前工作目录中,创建任意一个文件
[root@linux ~]# touch aliyun.txt
[root@linux ~]# ls
aliyun.txt cdc conf dintalk docker habur jenkins music music1 mysql nginx total version
3.2 在当前工作目录中,创建有序的10个文件并以 txt 为后缀
[root@linux ~]# touch xin{1..10}.txt
[root@linux ~]# ls
cdc habur mysql xin10.txt xin4.txt xin8.txt
conf jenkins nginx xin1.txt xin5.txt xin9.txt
dintalk music total xin2.txt xin6.txt
docker music1 version xin3.txt xin7.txt
3.3 修改指定文件的查看时间和修改时间
[root@linux ~]# touch -d "2023-03-22 17:30" aliyun.txt
[root@linux ~]# stat aliyun.txt
文件:"aliyun.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:33654918 硬链接:2
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2023-03-22 17:30:00.000000000 +0800
最近更改:2023-03-22 17:30:00.000000000 +0800
最近改动:2023-03-22 17:35:00.503471853 +0800
创建时间:-