您的位置:首页 > 其它

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

2015-07-21 20:48 405 查看
   之前在讲 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: