Linux find查找文件命令详解

语法:find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path…] [expression]

选项:
-P
不跟随符号链接(默认选项)。
-L
跟随符号链接。

表达式:
表达式由options,tests,actions组成。
OPTIONS:
-daystart
Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago. This option only affects tests which appear later on the command line.
-version, –version
Print the find version number and exit.
-help, –help
Print a summary of the command-line usage of find and exit.
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directo-
ries below the command line arguments. -maxdepth 0
means only apply the tests and actions to the command line argu-
ments.

-mindepth levels
Do not apply any tests or actions at levels less than levels (a
non-negative integer). -mindepth 1 means process all files except
the command line arguments.

TESTS:
-amin n
文件最后访问时间n分钟前。
-anewer file
比file最后访问时间早。
-atime n
文件最后访问时间为 n*24前。-atime +1表示最后访问时间至少为两天前。
-cmin n
文件状态最后修改为n分钟前。
-cnewer file
文件状态最后修改时间比file早。
-ctime n
文件状态最后修改时间为 n*24前。
-empty
文件为空,且文件为一般文件或目录。
-executable
文件为可执行文件。
-gid n
文件gid。
-group gname
文件组名。
-mmin n
文件内容n分钟前被修改。
-mtime n
文件内容n*24小时前被修改。
-name pattern
以文件名搜索文件。
-newer file
文件内容最后修改时间比file早。
-nogroup
无有效gid的文件。
-nouser
无有效uid的文件。
-path pattern
匹配路径。
-perm mode
确切的权限,如-perm 600表示查找权限为600的文件。
-perm -mode
至少包含的权限,如-perm -600表示用户对文件至少有读写权限,可以匹配600,也可以匹配640 644等。
-size n[cwbkMG]
‘b’
n个512字节的block(默认)
‘c’
字节
‘w’
双字节
‘k’
千字节
‘M’
兆字节
‘G’
千兆字节
-type c
文件类型:
b
块文件
c
字符文件
d
目录
p
FIFO文件
f
常规文件
l
符号链接文件
s
socket文件
-uid n
uid为n的文件
-user uname
用户名为uname的文件
ACTIONS:
-delete
删除文件
-exec command ;
执行的命令,{}表示找出的文件名,在不同的linux,后面的分号可以需要\;
-print
打印文件全名,以分行符分隔
-print0,以空格分隔。
-quit
立即退出,find /tmp/foo /tmp/bar -print -quit表示只列出/tmp/foo。
操作符:
( expr )
优先执行
! expr
非运算
-not expr
同 ! expr
expr1 expr2
与运算
expr1 -a expr2或者expr1 -and expr2
与运算
expr1 -o expr2 或者expr1 -or expr2
或运算

标签:Linux 发布于:2019-10-06 16:14:48