shell脚本中特殊筛选文件

问题描述:在写shell中,总会遇到一些各式各样筛选文件的需求,整理了一些特殊情况

 

1.查找目标文件下大于100Mb的文件

find $target_dir -type f -size +70M

 

2.查找目标文件下大于100Mb的文件,并显示详细信息

find $target_dir -type f -size +300M  -print0 | xargs -0 ls -ltrh

 

3.查找文件不缺分大小写

find $target_dir -iname "$file*.zip"

 

4.查找目标文件下所有的*.zip文件,并且排除掉几个目标*.zip文件

find $target_dir -iname "$file*.zip" -type f -mtime +0 -mtime -2 -not -name '*-test.zip' -not -name '*-mysql.zip' -not -name '*-information_schema.zip' -not -name '*-sys.zip'

 

5.查找目标文件下最新的目录

find $target_dir -type d -printf '%T@ %p\n' | sort -n | tail -n 1 | awk '{print $2}'

 

6.获取目标文件下最新的一个*.zip文件

ls -ltd $target_dir/* | grep -E all-database-.*zip | head -n1 | awk '{print $9}'

 

7.查找目标文件下7天前的*.zip文件

find $target_dir -iname "all-database-$file*.zip" -type f -mtime +0 -mtime -7

 

8.查找目标文件下的所有文件,目标层级为0,不向下递归

find $target_dir -path test -prune -o -maxdepth 0 -type d

 

posted @   我爱睡莲  阅读(142)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
历史上的今天:
2022-05-31 python:生成半年内的巡检日报execl
点击右上角即可分享
微信分享提示