UNIXでファイルのmtimeを手動で更新する

UNIXでファイルのmtimeを手動で更新する

UNIX システム上のファイルの日付を手動で (以前の日付に) 変更することは可能ですか?

もしそうなら、この問題にどう対処すればいいでしょうか?

複数のファイルに対して同時に同じことを実行するにはどうすればよいでしょうか?

答え1

タッチを使うこともできます。例:

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

または、もっと簡単な方法として、すでに mtime が含まれている file2 がある場合は、-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」をお読みください。

それが役に立つことを願います。

関連情報