DEV Community

Dang Hoang Nhu Nguyen
Dang Hoang Nhu Nguyen

Posted on

2 2

[BTY] Day 5: ctime() does not refer to creation time

This post was for 08.02.2022

In Python, I usually retrieve ctime (means creation time for me) of a file using the following code:

from pathlib import Path
f = Path(file_path). # file_path is the path to any files in your system
file_stat = f.stat()
print(file_stat.st_ctime)
Enter fullscreen mode Exit fullscreen mode

BUT,

I've got troubles when relying on this approach, because:

ctime() does not refer to creation time on *nix systems, but rather the last time the inode data changed.

I found this from this answer: https://stackoverflow.com/a/237084/6563277

The reason is that I have modified ctime by doing something to the inode: chmod and chown on the file.

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay