多学一点(九)——使用touch命令创建指定时间的文件

   之前在讲 find 命令时提到过其-newer -anewer -cnewer 参数,可以用这些参数查找某个时间段内的文件。但往往我们没有两个想要使用的准确的时间节点文件,这就需要用到接下来要介绍的用 touch 命令创建指定 atime mtime 的文件。

   (1-t 参数:指定文件atime mtime,可以使用 197011日到指定日期的毫秒数,也可以直接使用日期,格式为 [[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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章