linux 使用 touch 修改文件的修改时间

https://www.akii.org/linux-touch-change-file-modify-time.html

rsync有时候因为服务器时间错了,需要更改文件的修改时间时间,可以使用 touch命令来修改文件的修改时间:

1
touch -c -m -t 201101110000 teadme.txt

修改readme.txt为2011年1月11日零时零分修改

如果批量修改文件和目录,则使用

1
find /home/www/site - exec touch -c -m -t 201101110000 {} \;

即可把/home/www/site下的所有文件和目录都改变修改时间。

注意上面命令中的空格。

touch [-acdmt] 文件参数:

-a : 仅修改access time。

-c : 仅修改时间,而不建立文件。

-d : 后面可以接日期,也可以使用 –date=”日期或时间”

-m : 仅修改mtime。

-t : 后面可以接时间,格式为 [YYMMDDhhmm]

如 touch -c -t 0906270730 file

Usage: touch [OPTION]… FILE…
Update the access and modification times of each FILE to the current time.

Mandatory arguments to long options are mandatory for short options too.
-a change only the access time
-c, –no-create do not create any files
-d, –date=STRING parse STRING and use it instead of current time
-f (ignored)
-m change only the modification time
-r, –reference=FILE use this file’s times instead of current time
-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time
–time=WORD change the specified time:
WORD is access, atime, or use: equivalent to -a
WORD is modify or mtime: equivalent to -m
–help display this help and exit
–version output version information and exit

Note that the -d and -t options accept different time-date formats.

If a FILE is -, touch standard output.

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值