find之mtime、ctime、atime、daystart用法示例
文章目录
1 参数解释
-atime:最后一次读的时间戳;
-mtime:最后一次修改内容的时间戳;
-ctime:最后一次修改文件属性的时间戳,比如文件的owner和group;修改内容也会修改ctime。
#
-daystart:从今天开始而不是从24小时前开始计算时间,默认-amin、-atime、-cmin、-cime、-mmin、-mtime 按24小时计算。此选项仅影响后面的参数,故-mtime、-ctime等需要放在-daystart参数的后面
2 以mtime参数举例
# 天:按24小时算
1、-mtime n : 在n天之前的“一天之内”被更改过内容的文件
2、-mtime +n : 在n天之前(不含n天本身)被更改过内容的文件名
3、-mtime -n : 在n天之内(含n天本身)被更改过内容的文件名
# 天:按自然天算
1、-daystart -mtime n : 在n天之前的“一天之内”被更改过内容的文件
2、-daystart -mtime +n : 在n天之前(不含n天本身)被更改过内容的文件名
3、-daystart -mtime -n : 在n天之内(含n天本身)被更改过内容的文件名
3 实践:无【-daystart】选项
[root@pgm-10-1-1-182 log]# date
2023年 03月 07日 星期二 14:23:18 +07
[root@pgm-10-1-1-182 log]#
# 从当前时间算起,24小时之前的 24小时之内
[root@pgm-10-1-1-182 log]# find ./ -mtime 1 -name '*log' -exec ls -l {} \; | sort -b
-rw------- 1 postgres postgres 0 3月 5 15:00 ./postgresql-2023-03-05_150000.log
-rw------- 1 postgres postgres 0 3月 5 16:00 ./postgresql-2023-03-05_160000.log
-rw------- 1 postgres postgres 0 3月 5 17:00 ./postgresql-2023-03-05_170000.log
-rw------- 1 postgres postgres 0 3月 5 18:00 ./postgresql-2023-03-05_180000.log
-rw------- 1 postgres postgres 0 3月 5 19:00 ./postgresql-2023-03-05_190000.log
-rw------- 1 postgres postgres 0 3月 5 20:00 ./postgresql-2023-03-05_200000.log
-rw------- 1 postgres postgres 0 3月 5 21:00 ./postgresql-2023-03-05_210000.log
-rw------- 1 postgres postgres 0 3月 5 22:00 ./postgresql-2023-03-05_220000.log
-rw------- 1 postgres postgres 0 3月 5 23:00 ./postgresql-2023-03-05_230000.log
-rw------- 1 postgres postgres 0 3月 6 00:00 ./postgresql-2023-03-06_000000.log
-rw------- 1 postgres postgres 0 3月 6 01:00 ./postgresql-2023-03-06_010000.log
-rw------- 1 postgres postgres 0 3月 6 02:00 ./postgresql-2023-03-06_020000.log
-rw------- 1 postgres postgres 0 3月 6 03:00 ./postgresql-2023-03-06_030000.log
-rw------- 1 postgres postgres 0 3月 6 04:00 ./postgresql-2023-03-06_040000.log
-rw------- 1 postgres postgres 0 3月 6 05:00 ./postgresql-2023-03-06_050000.log
-rw------- 1 postgres postgres 0 3月 6 06:00 ./postgresql-2023-03-06_060000.log
-rw------- 1 postgres postgres 0 3月 6 07:00 ./postgresql-2023-03-06_070000.log
-rw------- 1 postgres postgres 0 3月 6 08:00 ./postgresql-2023-03-06_080000.log
-rw------- 1 postgres postgres 0 3月 6 09:00 ./postgresql-2023-03-06_090000.log
-rw------- 1 postgres postgres 0 3月 6 10:00 ./postgresql-2023-03-06_100000.log
-rw------- 1 postgres postgres 0 3月 6 11:00 ./postgresql-2023-03-06_110000.log
-rw------- 1 postgres postgres 0 3月 6 12:00 ./postgresql-2023-03-06_120000.log
-rw------- 1 postgres postgres 0 3月 6 13:00 ./postgresql-2023-03-06_130000.log
-rw------- 1 postgres postgres 0 3月 6 14:00 ./postgresql-2023-03-06_140000.log
# 从当前时间算起,24小时之内
[root@pgm-10-1-1-182 log]# find ./ -mtime -1 -name '*log' -exec ls -l {} \; | sort -b
-rw------- 1 postgres postgres 0 3月 6 15:00 ./postgresql-2023-03-06_150000.log
-rw------- 1 postgres postgres 0 3月 6 16:00 ./postgresql-2023-03-06_160000.log
-rw------- 1 postgres postgres 0 3月 6 17:00 ./postgresql-2023-03-06_170000.log
-rw------- 1 postgres postgres 0 3月 6 18:00 ./postgresql-2023-03-06_180000.log
-rw------- 1 postgres postgres 0 3月 6 19:00 ./postgresql-2023-03-06_190000.log
-rw------- 1 postgres postgres 0 3月 6 20:00 ./postgresql-2023-03-06_200000.log
-rw------- 1 postgres postgres 0 3月 6 21:00 ./postgresql-2023-03-06_210000.log
-rw------- 1 postgres postgres 0 3月 6 22:00 ./postgresql-2023-03-06_220000.log
-rw------- 1 postgres postgres 0 3月 6 23:00 ./postgresql-2023-03-06_230000.log
-rw------- 1 postgres postgres 0 3月 7 00:00 ./postgresql-2023-03-07_000000.log
-rw------- 1 postgres postgres 0 3月 7 01:00 ./postgresql-2023-03-07_010000.log
-rw------- 1 postgres postgres 0 3月 7 02:00 ./postgresql-2023-03-07_020000.log
-rw------- 1 postgres postgres 0 3月 7 03:00 ./postgresql-2023-03-07_030000.log
-rw------- 1 postgres postgres 0 3月 7 04:00 ./postgresql-2023-03-07_040000.log
-rw------- 1 postgres postgres 0 3月 7 05:00 ./postgresql-2023-03-07_050000.log
-rw------- 1 postgres postgres 0 3月 7 06:00 ./postgresql-2023-03-07_060000.log
-rw------- 1 postgres postgres 0 3月 7 07:00 ./postgresql-2023-03-07_070000.log
-rw------- 1 postgres postgres 0 3月 7 08:00 ./postgresql-2023-03-07_080000.log
-rw------- 1 postgres postgres 0 3月 7 09:00 ./postgresql-2023-03-07_090000.log
-rw------- 1 postgres postgres 0 3月 7 10:00 ./postgresql-2023-03-07_100000.log
-rw------- 1 postgres postgres 0 3月 7 11:00 ./postgresql-2023-03-07_110000.log
-rw------- 1 postgres postgres 0 3月 7 12:00 ./postgresql-2023-03-07_120000.log
-rw------- 1 postgres postgres 0 3月 7 13:00 ./postgresql-2023-03-07_130000.log
-rw------- 1 postgres postgres 0 3月 7 14:00 ./postgresql-2023-03-07_140000.log
# 从当前时间算起,24小时之内
[root@pgm-10-1-1-182 log]# find ./ -mtime 0 -name '*log' -exec ls -l {} \; | sort -b
-rw------- 1 postgres postgres 0 3月 6 15:00 ./postgresql-2023-03-06_150000.log
-rw------- 1 postgres postgres 0 3月 6 16:00 ./postgresql-2023-03-06_160000.log
-rw------- 1 postgres postgres 0 3月 6 17:00 ./postgresql-2023-03-06_170000.log
-rw------- 1 postgres postgres 0 3月 6 18:00 ./postgresql-2023-03-06_180000.log
-rw------- 1 postgres postgres 0 3月 6 19:00 ./postgresql-2023-03-06_190000.log
-rw------- 1 postgres postgres 0 3月 6 20:00 ./postgresql-2023-03-06_200000.log
-rw------- 1 postgres postgres 0 3月 6 21:00 ./postgresql-2023-03-06_210000.log
-rw------- 1 postgres postgres 0 3月 6 22:00 ./postgresql-2023-03-06_220000.log
-rw------- 1 postgres postgres 0 3月 6 23:00 ./postgresql-2023-03-06_230000.log
-rw------- 1 postgres postgres 0 3月 7 00:00 ./postgresql-2023-03-07_000000.log
-rw------- 1 postgres postgres 0 3月 7 01:00 ./postgresql-2023-03-07_010000.log
-rw------- 1 postgres postgres 0 3月 7 02:00 ./postgresql-2023-03-07_020000.log
-rw------- 1 postgres postgres 0 3月 7 03:00 ./postgresql-2023-03-07_030000.log
-rw------- 1 postgres postgres 0 3月 7 04:00 ./postgresql-2023-03-07_040000.log
-rw------- 1 postgres postgres 0 3月 7 05:00 ./postgresql-2023-03-07_050000.log
-rw------- 1 postgres postgres 0 3月 7 06:00 ./postgresql-2023-03-07_060000.log
-rw------- 1 postgres postgres 0 3月 7 07:00 ./postgresql-2023-03-07_070000.log
-rw------- 1 postgres postgres 0 3月 7 08:00 ./postgresql-2023-03-07_080000.log
-rw------- 1 postgres postgres 0 3月 7 09:00 ./postgresql-2023-03-07_090000.log
-rw------- 1 postgres postgres 0 3月 7 10:00 ./postgresql-2023-03-07_100000.log
-rw------- 1 postgres postgres 0 3月 7 11:00 ./postgresql-2023-03-07_110000.log
-rw------- 1 postgres postgres 0 3月 7 12:00 ./postgresql-2023-03-07_120000.log
-rw------- 1 postgres postgres 0 3月 7 13:00 ./postgresql-2023-03-07_130000.log
-rw------- 1 postgres postgres 0 3月 7 14:00 ./postgresql-2023-03-07_140000.log
4 实践:有【-daystart】选项
[root@pgm-10-1-1-182 log]# date
2023年 03月 07日 星期二 14:23:18 +07
[root@pgm-10-1-1-182 log]#
# 从今天自然天算起,一天前的 一天之内
[root@pgm-10-1-1-182 log]# find ./ -daystart -mtime 1 -name '*log' -exec ls -l {} \; | sort -b
-rw------- 1 postgres postgres 0 3月 6 00:00 ./postgresql-2023-03-06_000000.log
-rw------- 1 postgres postgres 0 3月 6 01:00 ./postgresql-2023-03-06_010000.log
-rw------- 1 postgres postgres 0 3月 6 02:00 ./postgresql-2023-03-06_020000.log
-rw------- 1 postgres postgres 0 3月 6 03:00 ./postgresql-2023-03-06_030000.log
-rw------- 1 postgres postgres 0 3月 6 04:00 ./postgresql-2023-03-06_040000.log
-rw------- 1 postgres postgres 0 3月 6 05:00 ./postgresql-2023-03-06_050000.log
-rw------- 1 postgres postgres 0 3月 6 06:00 ./postgresql-2023-03-06_060000.log
-rw------- 1 postgres postgres 0 3月 6 07:00 ./postgresql-2023-03-06_070000.log
-rw------- 1 postgres postgres 0 3月 6 08:00 ./postgresql-2023-03-06_080000.log
-rw------- 1 postgres postgres 0 3月 6 09:00 ./postgresql-2023-03-06_090000.log
-rw------- 1 postgres postgres 0 3月 6 10:00 ./postgresql-2023-03-06_100000.log
-rw------- 1 postgres postgres 0 3月 6 11:00 ./postgresql-2023-03-06_110000.log
-rw------- 1 postgres postgres 0 3月 6 12:00 ./postgresql-2023-03-06_120000.log
-rw------- 1 postgres postgres 0 3月 6 13:00 ./postgresql-2023-03-06_130000.log
-rw------- 1 postgres postgres 0 3月 6 14:00 ./postgresql-2023-03-06_140000.log
-rw------- 1 postgres postgres 0 3月 6 15:00 ./postgresql-2023-03-06_150000.log
-rw------- 1 postgres postgres 0 3月 6 16:00 ./postgresql-2023-03-06_160000.log
-rw------- 1 postgres postgres 0 3月 6 17:00 ./postgresql-2023-03-06_170000.log
-rw------- 1 postgres postgres 0 3月 6 18:00 ./postgresql-2023-03-06_180000.log
-rw------- 1 postgres postgres 0 3月 6 19:00 ./postgresql-2023-03-06_190000.log
-rw------- 1 postgres postgres 0 3月 6 20:00 ./postgresql-2023-03-06_200000.log
-rw------- 1 postgres postgres 0 3月 6 21:00 ./postgresql-2023-03-06_210000.log
-rw------- 1 postgres postgres 0 3月 6 22:00 ./postgresql-2023-03-06_220000.log
-rw------- 1 postgres postgres 0 3月 6 23:00 ./postgresql-2023-03-06_230000.log
# 从今天自然天算起,一天之内
[root@pgm-10-1-1-182 log]# find ./ -daystart -mtime -1 -name '*log' -exec ls -l {} \; | sort -b
-rw------- 1 postgres postgres 0 3月 7 00:00 ./postgresql-2023-03-07_000000.log
-rw------- 1 postgres postgres 0 3月 7 01:00 ./postgresql-2023-03-07_010000.log
-rw------- 1 postgres postgres 0 3月 7 02:00 ./postgresql-2023-03-07_020000.log
-rw------- 1 postgres postgres 0 3月 7 03:00 ./postgresql-2023-03-07_030000.log
-rw------- 1 postgres postgres 0 3月 7 04:00 ./postgresql-2023-03-07_040000.log
-rw------- 1 postgres postgres 0 3月 7 05:00 ./postgresql-2023-03-07_050000.log
-rw------- 1 postgres postgres 0 3月 7 06:00 ./postgresql-2023-03-07_060000.log
-rw------- 1 postgres postgres 0 3月 7 07:00 ./postgresql-2023-03-07_070000.log
-rw------- 1 postgres postgres 0 3月 7 08:00 ./postgresql-2023-03-07_080000.log
-rw------- 1 postgres postgres 0 3月 7 09:00 ./postgresql-2023-03-07_090000.log
-rw------- 1 postgres postgres 0 3月 7 10:00 ./postgresql-2023-03-07_100000.log
-rw------- 1 postgres postgres 0 3月 7 11:00 ./postgresql-2023-03-07_110000.log
-rw------- 1 postgres postgres 0 3月 7 12:00 ./postgresql-2023-03-07_120000.log
-rw------- 1 postgres postgres 0 3月 7 13:00 ./postgresql-2023-03-07_130000.log
-rw------- 1 postgres postgres 0 3月 7 14:00 ./postgresql-2023-03-07_140000.log
# 从今天自然天算起,一天之内
[root@pgm-10-1-1-182 log]# find ./ -daystart -mtime 0 -name '*log' -exec ls -l {} \; | sort -b
-rw------- 1 postgres postgres 0 3月 7 00:00 ./postgresql-2023-03-07_000000.log
-rw------- 1 postgres postgres 0 3月 7 01:00 ./postgresql-2023-03-07_010000.log
-rw------- 1 postgres postgres 0 3月 7 02:00 ./postgresql-2023-03-07_020000.log
-rw------- 1 postgres postgres 0 3月 7 03:00 ./postgresql-2023-03-07_030000.log
-rw------- 1 postgres postgres 0 3月 7 04:00 ./postgresql-2023-03-07_040000.log
-rw------- 1 postgres postgres 0 3月 7 05:00 ./postgresql-2023-03-07_050000.log
-rw------- 1 postgres postgres 0 3月 7 06:00 ./postgresql-2023-03-07_060000.log
-rw------- 1 postgres postgres 0 3月 7 07:00 ./postgresql-2023-03-07_070000.log
-rw------- 1 postgres postgres 0 3月 7 08:00 ./postgresql-2023-03-07_080000.log
-rw------- 1 postgres postgres 0 3月 7 09:00 ./postgresql-2023-03-07_090000.log
-rw------- 1 postgres postgres 0 3月 7 10:00 ./postgresql-2023-03-07_100000.log
-rw------- 1 postgres postgres 0 3月 7 11:00 ./postgresql-2023-03-07_110000.log
-rw------- 1 postgres postgres 0 3月 7 12:00 ./postgresql-2023-03-07_120000.log
-rw------- 1 postgres postgres 0 3月 7 13:00 ./postgresql-2023-03-07_130000.log
-rw------- 1 postgres postgres 0 3月 7 14:00 ./postgresql-2023-03-07_140000.log
5 最后
爱你
版权声明:本文为zhf_sy原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。