os.utime

Dan Stromberg drsalists at gmail.com
Sun Mar 20 22:32:48 EDT 2011


On Sun, Mar 20, 2011 at 7:12 PM, Christian Heimes <lists at cheimes.de> wrote:

> 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.


Yes, I probably should've used a quantifier on my single example.


> However ctime is *not* the creation time stamp on
> POSIX OSes.
>

Well, it is, and it's not.  It was originally called "creation time", but
many today find "change time" a better description of what it actually does,
sort of retroactively changing what the "c" means.  This is because the
ctime reflects the change time of an inode, not of the file's content - but
most people don't really care what an inode is.  Sometimes that's the same
as the time at which the file was created, but it doesn't necessarily remain
so throughout the file's lifetime.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110320/e5542bdf/attachment-0001.html>


More information about the Python-list mailing list