码迷,mamicode.com
首页 > 系统相关 > 详细

Linux命令之touch

时间:2018-06-22 13:15:40      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:reference   csharp   hmm   实例   date   访问时间   所有者   特殊   使用   

touch [选项] … 文件 …

说明:将每个文件的访问时间和修改时间改为当前时间。如果文件不存在则会创建空文件,除非使用-c或-h选项。如果文件名为”-”则特殊处理,更改与标准输出相关的文件的访问时间。

(1).选项

-a 只更改访问时间

-c,--no-create 不创建任何文件

-d,--date=字符串 使用指定字符串表示时间而非当前时间

-f 忽略

-h,--no-dereference 只影响符号链接本身,而非符号链接所指示的目的地(当系统支持更改符号链接的所有者时,此选项才有用)

-m 只更改修改时间

-r,--reference=文件 使用指定文件的时间属性而非当前时间

-t STAMP 使用[[CC(世纪)]YY]MMDDhhmm[.ss]格式的时间而非当前时间

--time=WORD使用WORD指定的时间:access/atime/use都等于-a选项的效果,而modify/mtime等于-m选项的效果

(2).实例

用touch创建文件

[root@CentOS6 桌面]# ll
总用量 0
[root@CentOS6 桌面]# touch touch_test_file    //在当前目录下创建文件
[root@CentOS6 桌面]# ll
总用量 0
-rw-r--r--. 1 root root 0 6月  17 13:28 touch_test_file
[root@CentOS6 桌面]# mkdir mydir
[root@CentOS6 桌面]# touch mydir/touch_test_file    //在指定目录下创建文件
[root@CentOS6 桌面]# ls -l mydir/
总用量 0
-rw-r--r--. 1 root root 0 6月  17 13:28 touch_test_file

 使用-t选项更改文档时间

[root@CentOS6 桌面]# touch -t 06061806 touch_test_file 
[root@CentOS6 桌面]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 6月  17 13:28 mydir
-rw-r--r--. 1 root root    0 6月   6 18:06 touch_test_file

 使用将一个文档时间同步到另一个文档

[root@CentOS6 桌面]# touch touch_test_file2
[root@CentOS6 桌面]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 6月  17 13:28 mydir
-rw-r--r--. 1 root root    0 6月   6 18:06 touch_test_file
-rw-r--r--. 1 root root    0 6月  17 13:34 touch_test_file2
[root@CentOS6 桌面]# touch -r touch_test_file touch_test_file2
[root@CentOS6 桌面]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 6月  17 13:28 mydir
-rw-r--r--. 1 root root    0 6月   6 18:06 touch_test_file
-rw-r--r--. 1 root root    0 6月   6 18:06 touch_test_file2

以当前时间为参照,将将对过去的时间更改为文档时间

[root@CentOS6 桌面]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 6月  17 13:28 mydir
-rw-r--r--. 1 root root    0 6月   6 18:06 touch_test_file
-rw-r--r--. 1 root root    0 6月   6 18:06 touch_test_file2
[root@CentOS6 桌面]# touch -d "10 days ago" touch_test_file
[root@CentOS6 桌面]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 6月  17 13:28 mydir
-rw-r--r--. 1 root root    0 6月   7 13:38 touch_test_file
-rw-r--r--. 1 root root    0 6月   6 18:06 touch_test_file2

 

Linux命令之touch

标签:reference   csharp   hmm   实例   date   访问时间   所有者   特殊   使用   

原文地址:https://www.cnblogs.com/diantong/p/9212425.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!