Manually update the mtime of a file in UNIX

Solution 1:

You can use touch. E.g::

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

Or often easier, if you have a file2 which has already the mtime, you can copy the time with -r:

touch -r file2 file

There is also the -t option with its strange format:

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

Solution 2:

You can use

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

-m Change only the modification time -d (--date=STRING) with the date you want to put in

extracted from the manual:

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.

for more info you can read the touch manual, running man touch.

i hope that helps.