歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> linux中如何使用touch修改文件的修改時間

linux中如何使用touch修改文件的修改時間

日期:2017/3/3 16:13:41   编辑:關於Linux

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.

 

Copyright © Linux教程網 All Rights Reserved