Linux find命令atime/mtime/ctime参数

2021-12-27  本文已影响0人  87d6dc4b11a7

通过touch命令创建五个日志文件,在Linux系统中,一个文件有三个时间参数,分别是atime,mtime,ctime。

access time(atime):显示的是文件中的数据最后被访问的时间。

modify time(mtime):显示的是文件内容被修改的最后时间。当修改文件的内容数据的时候,就会更新这个时间,而更改权限或者属性,mtime不会改变,这就是和ctime的区别。

change time(ctime):显示的是文件的权限、拥有者、所属的组、链接数发生改变时的时间。当然当内容改变时也会随之改变。

[root@localhost ~]# mkdir test-find
[root@localhost ~]# cd test-find/
[root@localhost test-find]# ll
总用量 0
[root@localhost test-find]# touch -t 202112232300 log-20211223.log
[root@localhost test-find]# touch -t 202112242300 log-20211224.log
[root@localhost test-find]# touch -t 202112252300 log-20211225.log
[root@localhost test-find]# touch -t 202112262300 log-20211226.log
[root@localhost test-find]# touch log-20211227.log
[root@localhost test-find]# ll
总用量 0
-rw-r--r--. 1 root root 0 12月 23 23:00 log-20211223.log
-rw-r--r--. 1 root root 0 12月 24 23:00 log-20211224.log
-rw-r--r--. 1 root root 0 12月 25 23:00 log-20211225.log
-rw-r--r--. 1 root root 0 12月 26 23:00 log-20211226.log
-rw-r--r--. 1 root root 0 12月 27 22:03 log-20211227.log
[root@localhost test-find]#
[root@localhost test-find]# stat log-20211227.log
  文件:"log-20211227.log"
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:19755385    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2021-12-27 22:03:58.551728684 +0800
最近更改:2021-12-27 22:03:58.551728684 +0800
最近改动:2021-12-27 22:03:58.551728684 +0800
创建时间:-
[root@localhost test-find]# stat log-20211223.log
  文件:"log-20211223.log"
  大小:0               块:0          IO 块:4096   普通空文件
设备:fd00h/64768d      Inode:17783627    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2021-12-23 23:00:00.000000000 +0800
最近更改:2021-12-23 23:00:00.000000000 +0800
最近改动:2021-12-27 22:03:24.802123967 +0800
创建时间:-

当修改文件内容时,三个时间都发生了改变。

[root@localhost test-find]# vi log-20211223.log
[root@localhost test-find]#
[root@localhost test-find]# stat log-20211223.log
  文件:"log-20211223.log"
  大小:6               块:8          IO 块:4096   普通文件
设备:fd00h/64768d      Inode:17783678    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2021-12-27 22:34:27.752212034 +0800
最近更改:2021-12-27 22:34:27.752212034 +0800
最近改动:2021-12-27 22:34:27.753212023 +0800
创建时间:-

当修改文件权限时,只有ctime发生了改变。

[root@localhost test-find]# chmod g+w log-20211223.log
[root@localhost test-find]#
[root@localhost test-find]# stat log-20211223.log
  文件:"log-20211223.log"
  大小:6               块:8          IO 块:4096   普通文件
设备:fd00h/64768d      Inode:17783678    硬链接:1
权限:(0664/-rw-rw-r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2021-12-27 22:34:27.752212034 +0800
最近更改:2021-12-27 22:34:27.752212034 +0800
最近改动:2021-12-27 22:35:49.922277618 +0800
创建时间:-

当前时间27号22:03,
+2 表示的是查找 24号22:03前的文件
+3 表示的是查找 23号22:03前的文件
3 表示的是查找23号22:03 到 24号22:03 之间的文件
-3 表示的查找24号22:03 到 27号22:03之间的文件

[root@localhost test-find]# find -mtime +3 -type f
[root@localhost test-find]#
[root@localhost test-find]# find -mtime +2 -type f
./log-20211223.log
[root@localhost test-find]# find -mtime -3 -type f
./log-20211224.log
./log-20211225.log
./log-20211226.log
./log-20211227.log
[root@localhost test-find]# find -mtime 3 -type f
./log-20211223.log
上一篇 下一篇

猜你喜欢

热点阅读