在Linux中,使用find
命令查找特定时间范围内创建的文件时,需结合时间参数(如-ctime
、-mtime
、-newermt
)。
-
按天数范围查找:
find /path -type f -ctime +3 -ctime -7 # 查找3天到7天前状态变更的文件
-ctime
基于文件元数据变更时间(如权限、所有者),-mtime
基于文件内容修改时间。 -
按绝对时间范围查找(精确到分钟或日期):
find /path -type f -newermt "2023-01-01" ! -newermt "2023-01-08" # 1月1日到1月7日
使用
-newermt
指定起始时间,! -newermt
排除结束时间后的文件。 -
使用分钟级精度:
find /path -type f -mmin -60 # 过去60分钟内修改过的文件
注意:
- Linux文件系统通常不记录“创建时间”(birth time),部分系统(如ext4)支持
stat -c %W
查看,但需结合find -printf "%C@"
等参数。 - 优先使用
-mtime
或-ctime
替代创建时间,确保兼容性。