当前位置: 代码迷 >> 综合 >> 关于Linux中的几个时间变量atime,ctime,mtime
  详细解决方案

关于Linux中的几个时间变量atime,ctime,mtime

热度:27   发布时间:2023-12-08 10:00:48.0
Linux的文件系统通常包括change time,access time和modification time这3个时间标签。
linux man这么说明这3个变量:
st_atime
           Time when file data was last accessed. Changed by  the
           following   functions:   creat(),   mknod(),   pipe(),
           utime(2), and read(2).
st_mtime
           Time when data was last modified. Changed by the  fol-
           lowing  functions:  creat(), mknod(), pipe(), utime(),
           and write(2).
st_ctime
           Time when file status was last changed. Changed by the
           following   functions:   chmod(),   chown(),  creat(),
           link(2),  mknod(),  pipe(),  unlink(2),  utime(),  and
           write().

这是针对系统调用函数描述的,在实际shell命令中,
  • touch 影响 atime和mtime,可以通过选项开关选择;
  • ls未加选项时,time一栏显示的是mtime;
  • chmod,chown,chgrp影响ctime;
  • 读写操作通常影响atime和mtime;
本源来说,ctime标签由文件系统中inode结构保存;而atime和mtime由目录树保存。一般的参数中提到的,除非明确指出,都是“最后一次内容被修改时的时间”,e.g当执行find时的-newer和-older指的也是mtime。