os.utime

Christian Heimes lists at cheimes.de
Sun Mar 20 22:12:15 EDT 2011


Am 21.03.2011 01:40, schrieb Dan Stromberg:
> 1) If you want to set the ctime to the current time, you can os.rename() the
> file to some temporary name, and then quickly os.rename() it back.
> 
> 2) You can sort of set a file to have an arbitrary ctime, by setting the
> system's clock to what you need, and then doing the rename thing above -
> then restore the clock back to what it should be.
> 
> 3) You can also use some sort of tool that knows the details of how inodes
> are stored on disk.  You'll likely need to do this with the filesystem
> unmounted at the time, though if the inode isn't currently cached in RAM,
> you might be able to get away without the umount and mount.
> 
> #2 and #3 require root access typically.

You don't have to renmae the file to set the ctime to current time
stamp. os.chmod(), os.chown(), os.link() and possible other function set
the ctime of a file. However ctime is *not* the creation time stamp on
POSIX OSes.

Christian




More information about the Python-list mailing list