linux 中atime、mtime、ctime

1、使用stat命令获取atime、mtime、ctime

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt
  File: a.txt
  Size: 10              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 12:00:07.113429738 +0800        ## 最后访问的时间
Modify: 2022-03-27 11:59:40.697435221 +0800        ## 最后修改的时间
Change: 2022-03-27 11:59:40.697435221 +0800        ## 最后改变的时间(属性、权限)
 Birth: -

 

2、atime因为系统性能的问题,已经不再每次访问实时更新了。https://www.cnblogs.com/liujiaxin2018/p/16062424.html

 

3、查看mtime、ctime

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt    ## 查看三种time
  File: a.txt
  Size: 10              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 12:00:07.113429738 +0800
Modify: 2022-03-27 11:59:40.697435221 +0800
Change: 2022-03-27 11:59:40.697435221 +0800
 Birth: -
root@ubuntu01:/home/test# date   ## 查看当前系统时间
2022年 03月 27日 星期日 12:10:09 CST
root@ubuntu01:/home/test# echo "xxxx" >> a.txt   ## 修改文件内容
root@ubuntu01:/home/test# stat a.txt   ## 查看修改和改变时间, 这说明对文件内容的修改直接影响 mtime和ctime
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 12:00:07.113429738 +0800
Modify: 2022-03-27 12:10:14.193446498 +0800
Change: 2022-03-27 12:10:14.193446498 +0800
 Birth: -

为什么修改文件内容ctime会发生改变?

当修改文件时,文件大小等也属于文件的属性,因此ctime也会改变。 

 

4、测试ctime

root@ubuntu01:/home/test# ls
a.txt
root@ubuntu01:/home/test# stat a.txt    ## 查看time
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 12:00:07.113429738 +0800
Modify: 2022-03-27 12:10:14.193446498 +0800
Change: 2022-03-27 12:10:14.193446498 +0800
 Birth: -
root@ubuntu01:/home/test# ll a.txt   ## 查看权限
-rw-r--r-- 1 root root 15 3月  27 12:10 a.txt
root@ubuntu01:/home/test# date   ## 系统时间
2022年 03月 27日 星期日 12:15:29 CST
root@ubuntu01:/home/test# chmod +x a.txt    ## 修改文件权限
root@ubuntu01:/home/test# ll a.txt         ## 查看权限
-rwxr-xr-x 1 root root 15 3月  27 12:10 a.txt*
root@ubuntu01:/home/test# stat a.txt   ## 统计时间, 说明对权限的修改只影响 ctime。
  File: a.txt
  Size: 15              Blocks: 8          IO Block: 4096   regular file
Device: 805h/2053d      Inode: 532492      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-27 12:00:07.113429738 +0800
Modify: 2022-03-27 12:10:14.193446498 +0800
Change: 2022-03-27 12:15:43.007038471 +0800
 Birth: -

 

posted @ 2022-03-27 12:19  小鲨鱼2018  阅读(237)  评论(0编辑  收藏  举报