Linux find command All In One
Linux find command All In One
Linux find
命令用来在指定目录下查找文件。
任何位于参数之前的字符串都将被视为欲查找的目录名。
如果使用该命令时,不设置任何参数,则 find 命令将在当前目录下查找子目录与文件。
并且将查找到的子目录和文件全部进行显示。
语法
# find [options] [path...] [expression]
$ find path -option [ -print ] [ -exec -ok command ] {} \;
参数
find 根据下列规则判断 path 和 expression,在命令列上第一个 - ( ) , ! 之前的部份为 path,之后的是 expression。如果 path 是空字串则使用目前路径,如果 expression 是空字串则使用 -print 为预设 expression。
expression 中可使用的选项有二三十个之多,在此只介绍最常用的部份。
-mount, -xdev : 只检查和指定目录在同一个文件系统下的文件,避免列出其它文件系统中的文件
-amin n : 在过去 n 分钟内被读取过
-anewer file : 比文件 file 更晚被读取过的文件
-atime n : 在过去 n 天内被读取过的文件
-cmin n : 在过去 n 分钟内被修改过
-cnewer file :比文件 file 更新的文件
-ctime n : 在过去 n 天内创建的文件
-mtime n : 在过去 n 天内修改过的文件
-empty : 空的文件-gid n or -group name : gid 是 n 或是 group 名称是 name
-ipath p, -path p : 路径名称符合 p 的文件,ipath 会忽略大小写
-name name, -iname name : 文件名称符合 name 的文件。iname 会忽略大小写
-size n : 文件大小 是 n 单位,b 代表 512 位元组的区块,c 表示字元数,k 表示 kilo bytes,w 是二个位元组。
-type c : 文件类型是 c 的文件。
d: 目录
c: 字型装置文件
b: 区块装置文件
p: 具名贮列
f: 一般文件
l: 符号连结
s: socket
-pid n : process id 是 n 的文件
你可以使用 ( ) 将运算式分隔,并使用下列运算。
exp1 -and exp2
! expr
-not expr
exp1 -or exp2
exp1, exp2
demos
$ find -L /var/www -name "*.js"
$ find /home/xgqfrms -type f -name document.pdf
$ find /home/xgqfrms -type f -iname document.pdf
$ find /var/log/nginx -type f -name '*.log.gz'
$ find /var/log/nginx -type f -not -name '*.log.gz'
linux remove matched files in follder
$ ls -R
$ ls -R | grep ".map"
$ find . -name '*.map' -delete
$ find ./ -name ".orig" -exec rm -rf {} \;
https://askubuntu.com/questions/43709/how-do-i-remove-all-files-that-match-a-pattern
https://superuser.com/questions/112078/delete-matching-files-in-all-subdirectories
https://unix.stackexchange.com/questions/84852/delete-files-matching-pattern
https://www.cyberciti.biz/faq/linux-unix-how-to-find-and-remove-files/
https://linuxize.com/post/how-to-remove-files-and-directories-using-linux-command-line/
refs
find command
https://www.runoob.com/linux/linux-comm-find.html
https://linuxize.com/post/how-to-find-files-in-linux-using-the-command-line/
https://linuxize.com/post/find-large-files-in-linux/
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16910082.html
未经授权禁止转载,违者必究!