gpt4 book ai didi

linux - 为什么在目录中创建新文件时目录的更改时间(ctime)会发生变化?

转载 作者:行者123 更新时间:2023-12-04 10:32:03 24 4
gpt4 key购买 nike

根据documentation :

Change time (ctime) This marks when a file's metadata was changed, such as permissions or ownership. This is also known as the "update" time in some documentation.



然而,当我在目录中创建一个新文件并运行 istat 时之后对目录执行命令我注意到目录的 ctime 又名“更新”时间已更改。我认为只有在更改目录的元数据时 ctime 才会更改?

最佳答案

根据 stat()系统调用规范:

The stat() function shall update any time-related fields (as described in XBD File Times Update), before writing into the stat structure.



在对应的 File Times Update文档:

Each function or utility in POSIX.1-2017 that reads or writes data (even if the data does not change) or performs an operation to change file status (even if the file status does not change) indicates which of the appropriate timestamps shall be marked for update.



POSIX system calls名单包含以下与在目录内创建对象相关的调用:
  • link()

    Upon successful completion, link() shall mark for update the last file status change timestamp of the file. Also, the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update.

  • mkdir()

    Upon successful completion, mkdir() shall mark for update the last data access, last data modification, and last file status change timestamps of the directory. Also, the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update.

  • mkfifo()

    Upon successful completion, mkfifo() shall mark for update the last data access, last data modification, and last file status change timestamps of the file. Also, the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update.

  • mknod()

    Upon successful completion, mknod() shall mark for update the last data access, last data modification, and last file status change timestamps of the file. Also, the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update.

  • open()

    If O_CREAT is set and the file did not previously exist, upon successful completion, open() shall mark for update the last data access, last data modification, and last file status change timestamps of the file and the last data modification and last file status change timestamps of the parent directory.

  • symlink()

    Upon successful completion, symlink() shall mark for update the last data access, last data modification, and last file status change timestamps of the symbolic link. Also, the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update.

  • 关于linux - 为什么在目录中创建新文件时目录的更改时间(ctime)会发生变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60372182/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com