find常用

it2025-01-30  14

find 标准格式: find pathname -options [-print -exec -ok …] 使用find删除操作: eg1 find /data -type f -name ‘‘*.txt’’ -mtime -7 -exec rm {} ;

eg2 find /data -type f -name ‘‘*.txt’’ -mtime -7 |xargs rm -f

(删除 /data目录下所有名字以‘.txt’结尾最近7天的文件)

-type后接类型,(f(file文件),d(directory目录),c(character字符),b(block块设备)) -name后接需找到的名称 (若使用-iname则不区分查找名称的大小写) -mtime接时间,按修改时间查找,-7 近七天,7 第七天,+7 七天前 (-amin -60最近60分钟、) xargs指将find到的内容做成一行传给后面的rm -f命令

ps find多个目录查找:find ./test ./dir2 -type f -name “abc*”

权限指定查找:-perm /u=r(查找只读) -perm /a=x(查找可执行) 大小指定查找: find / -size +50M -size -100M 空文件:find /tmp -type f -empty 空目录:find ~/ -type d -empty

最新回复(0)