Change file creation date
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))
Hanut
Updated on February 14, 2020Comments
-
Hanut over 4 years
Can I change creation date of some file using Python in Linux?
-
Hanut almost 15 years>Set the access and modified times But i need creating date.
-
Epcylon almost 15 yearsQuote 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 almost 15 yearsIt would be nice to add that there the concept of file creation date does not exist in most native *nix filesystems.
-
jfs over 8 yearsNote: there is
st_birthtime
on some Unix systems such as FreeBSD. -
jfs over 8 yearsit doesn't change creation time as @Nadia Alramli's answer explicitly says.
-
jfs over 6 yearsyou can extract crtime from ext4 fs using xstat function
-
Gringo Suave over 5 yearsIt's no longer true that Linux no longer supports creation time. See my answer below.
-
mirh over 4 yearsThe 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 about 2 yearsdid you ever created it? I would like to modify ctimes in Linux