find 命令参数mtime atime ctime使用说明

参数说明

  • atime –access time 访问时间,可通过cat、 more修改
  • ctime –change status time 修改状态位时间。可通过访问权限chmod chown、重命名 remane等命令修改
  • mtime –modify data time 修改文件数据时间
#修改mtime:
touch -mt YYMMDDhhmm filename   /****时间格式为年月日时分
#修改atime: 
touch -at YYMMDDhhmm filename

结合find使用方法

#使用find命令查找最近24小时修改过的文件
find $HOME -mtime 0

man find 中关于在mtime后面的数字的说明:

Search for files in your home directory which have been modified in the last twenty-four hours. This command works this way because the time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.

Numeric arguments can be specified as
+n for greater than n,
-n for less than n,
n for exactly n.

重点在上面加黑中的内容:每满24小时计1,多余的会舍去

比如过去10个小时的改动,因为10小于24,系统自动记录为0,写成find $HOME -mtime 0 格式,就可查找出过去24小时内的改动,自然也包括10小时内的。也可以写成find $HOME -mtime -1

总结如下:
n=0 表示时间是0<=time<24小时
n=1 表示时间是24<=time<48 所以+1至少要48
n=2 表示时间是48<=time<72

…依此类推

Leave a Reply

Your email address will not be published. Required fields are marked *