Linux运维入坑之路--find查找

find 命令用于在指定目录中查找文件
【参数选项】
-name 按照文件名查找
-type 按照文件类型查找(b设备块,d目录,c字符设备文件,l符号链接文件,f普通文件)
-size 按照文件大小查找
-prune 查找时排除当前文件夹,不查找
-path 查找目录
-depth 查找文件时,首先查找当前文件/当前目录中的文件,然后再在其子目录当中查找
-maxdepth 后面跟数字,表示在当前目录下往下N层深度,1是指只查找本级目录,不往下级目录查找
-perm 按照文件权限来查找
-user 按照文件属主来查找
-group 按照文件属组来查找
-nouser 查找无效属主文件
-nogroup 查找无效属组文件
-mtime 按照对象内容修改时间查找
-atime 按照对象被访问的时间查找
-ctime 按对象状态被修改的时间去查找
-empty 查找大小为0的文件或空目录
-mount 在查找文件系统时不跨越mount的文件系统
-a 并且
-o 或者
! 非,可以用于排除筛选
-newer 比xxx文件新
-newermt 具体时间查询
 
【示例】
find / -name *.txt 查找根目录下以txt结尾的文件
find /test -name [0-9].txt 查找/test下所有以数字开头的txt文件
find / -name "profile" -o -name "passwd" 查找根目录下passwd文件和profile文件
 
find /test -type d txt 查找/test目录下的txt目录
 
find /test -size +10M 查找/test目录下大于10M的文件
 
find /test -perm 755 查找/test目录下权限为755的文件
 
find /test -newer 1.txt ! -newer 2.txt 查找/test目录下比1.txt新,但是比2.txt旧的文件
 
find /test -mtime +3 查找修改时间大于3天的文件
find /test -mtime -5 查找修改时间为5天以内的文件
 
find /test -type f -exec ls -l {} \; 查找文件类型为普通文件,并执行ls -l 命令
find /test -type f -exec rm {} \; 查找文件类型为普通文件,并执行rm操作
find /test -type f -name "*.txt" | xargs ls -l 查找名字为txt结尾的普通文件,并执行ls -l 命令,相对exec更方便
 
find imgs/ -newermt ‘2018-7-24 09:10‘ ! -newermt ‘2018-7-24 09:20‘ -exec cp {} last/ \;
将imgs文件夹中创建更新时间在 09:10到09:20的内容,拷贝到last文件夹中
 


Linux运维入坑之路--find查找

上一篇:Mac电脑数据被误删了怎么办,还能恢复吗


下一篇:Linux运维入坑之路--重定向