For a utility I'm developing it would be expedient if I could set all three the named dates associated with the files in some directory to some date in the past.
I know I can use touch
to set the access & modify dates, but I need all three to be the same (used as reference-point/date).
Is there a way I can do this (root-access ok)
Edit:
I found this: http://blog.commandlinekungfu.com/2010/02/episode-80-time-bandits.html which proposes (for ext2/3/4 only):
# debugfs -w -R 'set_inode_field /pathtofile ctime 200901010101' filedevice
where '200901010101' is a sample date-time; and this https://stackoverflow.com/a/5518031/15161 to find the 'filedevice' needed above:
df /pathtofile | awk 'NR == 2 {print $1}'
I have tried this on a test-file but the debugfs-call took too long and I Ctrl-C'd it. (So I don't really know if this will work...)
Another idea is possibly to use a VM with system-date set to the past date I want, but I don't know how to set that up.
This relates to (2) but does not use a VM, from http://www.shellhacks.com/en/Faking-a-Files-Access-Modify-and-Change-TimeStamps-in-Linux :
As a possible workaround you can set the system time to the ctime you want to impose, then touch the file and then restore the system time.
NOW=$(date) && date -s "2030-08-15 21:30:11" && touch file.txt && date -s "$NOW"
but I'm not sure how safe/risky this would be.