Linux touch命令用于修改文件或者目录的时间属性,包括存取时间和更改时间,若文件不存在,系统会建立一个新的文件
语法
touch [-acfm][-d<日期时间>][-r<参考文件或目录>] [-t<日期时间>][--help][--version][文件或目录…]
参数说明
- a 更改文件的读取时间记录
- m 更改文件的修改时间记录
- c 若目标文件不存在,不会建立新的文件
- d 设定时间,可以使用多种不同的格式
- r 使用参考文件或目录的时间时间记录
- t 设定时间
- --help 显示帮助信息
- --version 显示版本信息
示例
# test文件不存在, 这里直接创建test文件
[root@hostname] touch test
# 查看当前test修改时间为4月20日
[root@hostname] ll test
-rw-r--r-- 1 root root 0 Apr 20 21:58 test
# 更改test的文件的修改时间至20200401
[root@hostname ~]# touch -d 20200401 test
# 查看test修改时间已被修改为4月1日
[root@hostname ~]# ll test
-rw-r--r-- 1 root root 0 Apr 1 00:00 test