上一篇
📰 最新动态
2025年8月,Linux内核6.10版本正式加入find
命令的-timestamp-resolution
选项,可精确到纳秒级时间筛选!虽然日常用不到这么精细,但老方法依然可靠~
想象这些场景:
Linux的find
命令就是你的时间侦探!
find [路径] -type f [时间条件] -exec ls -lh {} \; > 结果.txt
💡 关键参数
-type f
:只找文件(用d
找目录) -mtime
:修改时间(最常用) -atime
:访问时间 -ctime
:状态变更时间 find /var/log -type f -mtime -7 -name "*.log" > ~/recent_logs.txt
🌟 技巧
-7
:7天内(不含7天整) +7
:7天前(不含7天整) 7
:正好7天前 find /home -type f -newermt "2025-08-01" ! -newermt "2025-08-16" -printf "%p\n" > august_files.txt
🚨 注意
-printf
自定义输出格式 find ~/Pictures -type f -atime -0.04 -name "*.jpg" | tee recent_pics.txt
⏱️ 时间换算
find /opt -mtime +30 > old_files.txt
find ~/Downloads -ctime -1 -exec ls -lh {} \; > new_downloads.txt
find /tmp -mmin -60 -printf '{"file":"%p","size":"%k KB"}\n' | jq -s . > hourly_tmp.json
find . -type f -mtime -7 ! -path "./cache/*"
find /backup -name "*.tar.gz" -mtime +180 -exec rm -v {} \; > deleted.log
find /data -amin -30 # 30分钟内访问过的文件 find /etc -cmin +120 # 2小时前状态变更的文件
Q:为什么-mtime
结果和ls -l
显示不一致?
A:-mtime
按24小时制计算,而ls
显示精确时间,用-mmin
更精准!
Q:如何找两个日期之间的文件?
A:组合使用-newermt
和! -newermt
:
find . -newermt "2025-07-01" ! -newermt "2025-08-01"
参数 | 含义 | 示例 |
---|---|---|
-mtime -n |
n天内修改过 | -mtime -7 |
-mtime +n |
n天前修改过 | -mtime +30 |
-newer file |
比file更新 | -newer reference.log |
-daystart |
按自然日计算 | -daystart -mtime -1 |
查找/var
目录下:
.bak
后缀find /var -type f -mtime +30 -size +10M ! -name "*.bak" -fprintf report.txt "%p\t%k KB\t%TD\n"
现在你已经是时间管理大师了!⏰ 下次文件失踪时,记得请出find
侦探~
本文由 尾柔煦 于2025-08-02发表在【云服务器提供商】,文中图片由(尾柔煦)上传,本平台仅提供信息存储服务;作者观点、意见不代表本站立场,如有侵权,请联系我们删除;若有图片侵权,请您准备原始证明材料和公证书后联系我方删除!
本文链接:https://vps.7tqx.com/wenda/519729.html
发表评论