linux中如何使用touch修改檔案的修改時間

來源:互聯網
上載者:User

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.

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.