In Mac OS X there appears to be four different timestamps associated with a file. These timestamps are not always updated independently from each other, but one can have some individual control with a bit of care and with use of touch
, SetFile
, and chown
(or chmod
). To see this, let's experiment and create a new file from the command prompt #
:
# touch a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "May 19 00:11:14 2015" "May 19 00:11:14 2015" "May 19 00:11:14 2015" "May 19 00:11:14 2015" 4096 0 0 a.txt
The first date listed is last access time (atime
), the second is last modification time (mtime
), the third is last status change (ctime
), the fourth is time of file creation (birth, Btime
), see man lstat
.
To modify access time (atime
) to a specified time use:
# touch -a -t201412312359.59 a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "Dec 31 23:59:59 2014" "May 19 00:11:14 2015" "May 19 00:11:46 2015" "May 19 00:11:14 2015" 4096 0 0 a.txt
To modify modification time (mtime
) and time of file creation (Btime
) to a specified time use:
# touch -m -t201312312359.59 a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "Dec 31 23:59:59 2014" "Dec 31 23:59:59 2013" "May 19 00:12:19 2015" "Dec 31 23:59:59 2013" 4096 0 0 a.txt
Apparently this also automatically updates the time of last status change (ctime
) to the current system time!
To modify only the time of creation/birth (Btime
) to a given time, use (as proposed by others above):
# SetFile -d "12/31/1999 23:59:59" a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "Dec 31 23:59:59 2014" "Dec 31 23:59:59 2013" "May 19 00:12:19 2015" "Dec 31 23:59:59 1999" 4096 0 0 a.txt
To modify only the time of last status change (ctime
) to the current system time use for example:
# chown username a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "Dec 31 23:59:59 2014" "Dec 31 23:59:59 2013" "May 19 00:13:45 2015" "Dec 31 23:59:59 1999" 4096 0 0 a.txt
where username
is the owner of the file (as reported by stat
or ls -l
). This doesn't change the ownership of the file, but accesses the file's inode and records this as a time of last status change. Unfortunately, it is not possible to specify the time explicitly here other than by changing the computer's time...
In summary, to be able to change the four timestamps independently, one may use (in this order for the last 3):
touch -a -tCCYYMMDDHH.SS <file>
touch -m -tCCYYMMDDHH.SS <file>
SetFile -d "MM/DD/CCYY HH:MM:SS" <file>
- [set system date]
chown username <file>
[revert to normal system date]
(Of course, resetting the system date may not be a risk-free operation, you've been warned.)