shell find 的一些参数用法示例
1、根据文件名查找#具体文件名
find /root -name index.html #模糊文件名查找
#查找以“.html”结尾的文件
find /root -name "*.html" #查找以“index”开头的文件
find /root -name "index*" 2、根据文件类型查找
#b/d/c/p/l/f 分别是块设备、目录、字符设备、管道、符号链接、普通文件
#查找文件(排除块设备、目录、字符设备、管道、符号链接)
find /root -type f #查找以“index”开头的文件(排除块设备、目录、字符设备、管道、符号链接)
find /root -name "index*" -type f 3、根据文件大小查询
#查找大于10M的文件
find /root -size +10M #查找小于10M的文件
find /root -size -10M #查找大小在10M到20M之间的文件
find /root -size +10M -a -size -20M 4、根据执行权限查找
#查找权限为777的文件
find /root -perm 777 5、根据文件所属状态查找
#查找文件所有者是mysql的文件
find /root -user mysql #查找文件所有者是mysql的目录
find /root -user mysql -a -type d #查找文件说有组是mysql的文件
find /root -group mysql #查找无效属主的文件
find / -nouser #查找无效属组的文件
find / -nogroup 6、根据时间查找
#atime:access time文件被读取或者执行的时间;
#ctime:change time文件状态改变时间;
#mtime:modify time文件内容被修改的时间;
#mmin、amin、cmin
#查找30天以前的log文件
find /data/ -mtime +30 -name "*.log" #查找30天以内的log文件
find /data/ -mtime -30 -name "*.log" #查找第30天的log文件
find /data/ -mtime 30 -name "*.log" #查找30分钟以前修改的log文件;
find /data/ -mmin+30 -name "*.log" #查找30分钟以内被访问的log文件
find /data/ -amin-30 -name "*.log" #查找第30分钟改变的log文件
find/data/ -cmin30 -name "*.log" 7、根据文件新旧查找
#查找比1.txt新的文件
find . -newer "1.txt" -type f #查找比1.txt旧的文件
find . ! -newer "1.txt" -type f #查找比1.txt新的比2.txt旧的文件
find . -newer "aa.txt" -a ! -newer "bb.txt" -type f 8、根据目录级别查找
#处理目录以前首先处理目录下的子内容
find /root -depth #不查找顶级目录
find /root -mindepth 1 #只查找到2级子目录
find /root -maxdepth 2 9、查找位于某一类型文件系统中的文件
#找存在于ext3文件系统的文件
find / -fstype ext3 10、查文件时不跨越文件系统mount点
#只在根的mount点查找1.txt的文件
find / -mount -name "1.txt" 11、在/home/bel目录下查找不在/home/bel/test1子目录之内的所有文件
find . -path "./test1"-prune -o -print12、-exec 、 -ok参数 #查询当天修改过的文件并显示
find . -mtime -1 -type f -exec ls -l {} \; #查询当天修改过的文件并询问是否要显示
find . -mtime -1 -type f -ok ls -l {} \; #查找/data目录以.log结尾,30天以前的文件,大小大于10M并复制到/tmp目录
find /data/ -name "*.log" -type f -mtime +30 -size +10M -exec cp {} /tmp/ \; #查找/data目录以.log结尾,30天以前的文件并删除
find /data/ -name "*.log" -type f -mtime +30 -delete
find /data/ -name "*.log" -type f -mtime +30 -exec rm -rf {} \;
页:
[1]