之前在講 find 命令時提到過其-newer , -anewer 和 -cnewer 參數,可以用這些參數查找某個時間段內的文件。但往往我們沒有兩個想要使用的準確的時間節點文件,這就需要用到接下來要介紹的用 touch 命令創建指定 atime 、 mtime 的文件。
(1)-t 參數:指定文件atime 和 mtime,可以使用 1970年1月1日到指定日期的毫秒數,也可以直接使用日期,格式爲 [[CC]YY]MMDDhhmm[.ss]:
[root@localhost ~]# touch -t 201003141036.30 oldfile
注意這裏的時間也可以使用引號引上,即:
[root@localhost ~]# touch -t "201003141036.30" oldfile
(2)-d 參數:與 -t 參數的作用相同,指定文件 atime 和 mtime,只是使用格式略有區別,使用字符串形式來指定時間:
[root@localhost ~]# touch -d "20020306"
[root@localhost ~]# touch -d "20020304 12:38"
(3)-r 參數:使用其他文件的atime 和 mtime 作爲該文件的atime 和 mtime:
[root@localhost ~]# touch -r oldfile newfile
(4)-a 參數:只修改atime ,對時間的設置不會影響到 mtime ,結合-d 或 -t 或 -r 使用:
[root@localhost ~]# touch -a -t 201003141036.30 oldfile
[root@localhost ~]# touch -r oldfile newfile -a
(5)-m 參數:只修改mtime,對時間的設置不會影響到 atime ,結合-d 或 -t 或 -r使用:
[root@localhost ~]# touch -m -t 201003141036.30 oldfile
[root@localhost ~]# touch -r oldfile newfile -m
注:touch 沒有相關參數來指定文件 ctime,即新創建的文件的 ctime 只能爲當前時間。
本文出自 “細桶假狗屎” 博客,請務必保留此出處http://xitongjiagoushi.blog.51cto.com/9975742/1632840