touch命令的功能是用于创建空文件与修改时间戳。如果文件不存在,则会创建出一个空内容的文本文件;如果文件已经存在,则会对文件的Atime(访问时间)和Ctime(修改时间)进行修改操作,管理员可以完成此项工作,而普通用户只能管理主机的文件。
语法格式:touch [参数] 文件
常用参数:
-a 改变档案的读取时间记录
-m 改变档案的修改时间记录
-r 使用参考档的时间记录,与 --file 的效果一样
-c 不创建新文件
-d 设定时间与日期,可以使用各种不同的格式
-t 设定档案的时间记录,格式与 date 命令相同
–no-create 不创建新文件
–help 显示帮助信息
–version 列出版本讯息
参考实例
创建出一个指定名称的空文件:
[root@linuxcool ~]# touch File.txt
结合通配符,创建出多个指定名称的空文件:
[root@linuxcool ~]# touch File{1…5}.txt
修改指定文件的查看时间和修改时间:
[root@linuxcool ~]# touch -d “2022-05-08 15:44” anaconda-ks.cfg
[root@linuxcool ~]# stat anaconda-ks.cfg
File: anaconda-ks.cfg
Size: 1256 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 35319937 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2022-05-08 15:44:00.000000000 +0800
Modify: 2022-05-08 15:44:00.000000000 +0800
Change: 2022-05-06 15:43:47.843170709 +0800
Birth: -
评论区