Is it possible to manually alter the date of a file on a UNIX system (to a previous date)?
If so, how would I tackle this problem?
How would I be able to do the same thing on multiple files at the same time?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityYou 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
-d
is not a valid option on an OS X machine.
– ukliviu
Jun 6 '13 at 9:46
-t
is POSIX so it's a good bet to be supported on most current unices.
– Wumpus Q. Wumbley
Jun 6 '13 at 10:02
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.
touch file
to make it have the current date. – fedorqui Jun 6 '13 at 9:38sudo date -s "sometime in the past"
, thentouch
it and go back to current date. – fedorqui Jun 6 '13 at 9:40-d
in touch. – fedorqui Jun 6 '13 at 9:42