linux命令-touch命令

touch命令

一、简介

touch命令将每个文件的访问时间和修改时间改为当前时间。

二、用法

touch [选项] ... 文件 ...

三、选项

  • -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 选项的效果

四、实例

1、在当前目录下建立一个空文件a.log
[root@VM_0_4_centos chenwei]# touch a.txt
[root@VM_0_4_centos chenwei]# ll
total 60
-rw-r--r-- 1 root    root       0 Jun 24 18:37 a.txt
2、更新a.log的修改时间为当前时间
[root@VM_0_4_centos chenwei]# touch a.txt
[root@VM_0_4_centos chenwei]# ll
total 60
-rw-r--r-- 1 root    root       0 Jun 24 18:38 a.txt
3、更新log1.log的时间和log2.log时间戳相同
[root@VM_0_4_centos chenwei]# touch case.sh -r a.txt
[root@VM_0_4_centos chenwei]# ll
total 60
-rw-r--r-- 1 root    root       0 Jun 24 18:38 a.txt
-rwxr--r-- 1 chenwei chenwei   99 Jun 24 18:38 case.sh
4、设置文件的时间戳
[root@VM_0_4_centos chenwei]# touch a.txt -t 201806241840.50 
[root@VM_0_4_centos chenwei]# ll
total 60
-rw-r--r-- 1 root    root       0 Jun 24 18:40 a.txt

五、参考

http://www.cnblogs.com/xqzt/p/5399407.html

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值