Is ctime always <= mtime?

前端 未结 5 1101
旧时难觅i
旧时难觅i 2021-02-14 13:38

When using os.stat() in Python, can I assume that st_ctime is always less then or equal to st_mtime? If not, why not?

The code will always run on Linux, but if there is

5条回答
  •  不知归路
    2021-02-14 14:13

    As @ketil says, ctime is updated when file metadata is changed.

    One way this can change is that if you move a file from one directory to another. ctime will change, but not mtime.

    touch test_file
    mv test_file another_directory/
    stat another_directory/test_file 
    

    gives

      File: `another_directory/test_file'
      Size: 0           Blocks: 0          IO Block: 4096   regular empty file
    Device: 80ah/2058d  Inode: 23183108    Links: 1
    Access: (0644/-rw-r--r--)  Uid: ( 1004/  agrimm)   Gid: ( 1004/  agrimm)
    Access: 2011-07-07 10:11:27.000000000 +1000
    Modify: 2011-07-07 10:11:27.000000000 +1000
    Change: 2011-07-07 10:11:43.000000000 +1000
    

提交回复
热议问题