Change file creation date

23,462

Solution 1

Linux and Unix file system stores :

File access, change and modification time (remember UNIX or Linux never stores file creation time, this is favorite question asked in UNIX/Linux sys admin job interview)

Understanding UNIX / Linux file systems

Solution 2

You can use os.utime to change access and modify time but not the creation date.

Solution 3

It's no longer true that Linux doesn't support creation time. See:

Note this specific answer to view C-code that displays the field:

If the author of that post can help I might be able to create a wrapper with ctypes to modify it from Python.

Solution 4

I am not a UNIX expert, so maybe I'm wrong, but I think that UNIX (or Linux) don't store file creation time.

Solution 5

Check out os.utime

os.utime(file_path,(new_atime,new_mtime))
Share:
23,462
Hanut
Author by

Hanut

Updated on February 14, 2020

Comments

  • Hanut
    Hanut over 4 years

    Can I change creation date of some file using Python in Linux?

  • Hanut
    Hanut almost 15 years
    >Set the access and modified times But i need creating date.
  • Epcylon
    Epcylon almost 15 years
    Quote from the docs on that function: "Set the access and modified times of the file specified by path." .. so you can't use it to set the creation date.
  • Ishbir
    Ishbir almost 15 years
    It would be nice to add that there the concept of file creation date does not exist in most native *nix filesystems.
  • jfs
    jfs over 8 years
    Note: there is st_birthtime on some Unix systems such as FreeBSD.
  • jfs
    jfs over 8 years
    it doesn't change creation time as @Nadia Alramli's answer explicitly says.
  • jfs
    jfs over 6 years
    you can extract crtime from ext4 fs using xstat function
  • Gringo Suave
    Gringo Suave over 5 years
    It's no longer true that Linux no longer supports creation time. See my answer below.
  • mirh
    mirh over 4 years
    The thing is, while ext4 do support this crtime attribute, AFAIU that's not supposed to hold the same meaning than in other (or just Windows?) file systems. It's a specific property of the inode, not the contents itself. And I think for this reason there isn't any API to change or set it (which was actually what OP had asked).
  • churchill
    churchill about 2 years
    did you ever created it? I would like to modify ctimes in Linux