在 UNIX 中手動更新檔案的 mtime

在 UNIX 中手動更新檔案的 mtime

是否可以手動更改 UNIX 系統上文件的日期(更改為先前的日期)?

如果是這樣,我將如何解決這個問題?

我如何能夠同時對多個文件執行相同的操作?

答案1

您可以使用觸摸。例如::

touch -d '2007-01-31 8:46:26' file

或者通常更容易,如果你有一個 file2 已經有 mtime,你可以使用 -r 複製時間:

touch -r file2 file

還有 -t 選項,其格式很奇怪:

touch -t [[CC]YY]MMDDhhmm[.ss] file

答案2

您可以使用

 touch -m -d '1 Jan 2006 12:34' test.txt

-m 僅更改修改時間 -d (--date=STRING) 為您要輸入的日期

從手冊中摘錄:

DATE STRING
       The  --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday".  A
       date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers.  An empty  string  indicates
       the beginning of the day.  The date string format is more complex than is easily documented here but is fully described in the info documentation.

欲了解更多信息,您可以閱讀觸摸手冊,running man touch。

我希望這有幫助。

相關內容