Get file creation time with Python on linux

后端 未结 7 1904
一向
一向 2020-12-16 11:31

os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime \"change time\" on POSIX. is there any function that return the creation tim

7条回答
  •  情深已故
    2020-12-16 12:05

    By lack of a good utility, I've created crtime.

    pip install crtime
    

    Then you can use it like:

    sudo crtime ./
    

    Would print:

    1552938281  /home/pascal/crtime/.gitignore
    1552938281  /home/pascal/crtime/README.md
    1552938281  /home/pascal/crtime/crtime
    1552938281  /home/pascal/crtime/deploy.py
    1552938281  /home/pascal/crtime/setup.cfg
    1552938281  /home/pascal/crtime/setup.py
    1552938961  /home/pascal/crtime/crtime.egg-info
    1552939447  /home/pascal/crtime/.git
    1552939540  /home/pascal/crtime/build
    1552939540  /home/pascal/crtime/dist
    

    Note that for large directories it will be easily 1000x faster than xstat above, as this creates a temporary file and then executes stat calls for all files at once.

    In python (don't forget you need to still call it with sudo on linux):

    from crtime import get_crtimes, get_crtimes_in_dir
    get_crtimes_in_dir("./")
    

提交回复
热议问题