How can I set a Unix file's ctime?
(I'd much prefer an answer in terms of Python. If there's no way to do it with standard Python, then I suppose C is OK too.)
(Note: I know that one can use os.utime to set a file's atime and mtime. I am interested in setting ctime.)
(Note2: I hope that there's an answer that works for any POSIXoid Unix, but if not, I'm interested in Darwin and Ubuntu.)
It is relatively trivial to set a files ctime to the current time. Just modify its mtime, flip a permission bit or even make a hardlink to it. It is, AFAIK, impossible to set a file's ctime to an arbitrary value using the system call API in any direct sort of way.
If you had root access you could set the system time, do something to the file to set the ctime to the current time, then set the system time back. Also you could bit-twiddle the inode data structure on disk. But both of these are really bad ideas for a whole host of reasons that I don't expect I should have to explain in detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With