# 匹配文件名字find -name '*.txt' # 在【当前目录】下【递归】寻找 txt 类型的文件find /home -name '*.txt' #在【指定的目录】(即/home)下寻找# 匹配文件大小 单位:bcwkMGfind /home -name '*.txt' -size 100k # 大小为 100k 的 txt 文件find /home -name '*.txt' +size 100k # 大小大于 100k 的 txt 文件find /home -name '*.txt' -size 100k # 大小小于 100k 的 txt 文件# 匹配所属用户find /home -name '*.txt' -user ronnie # 所有属于 ronnie 的 txt 文件# 取反find /home -name '*.txt' -not -user ronnie # 所有不属于 ronnie 的 txt 文件# 匹配权限# ugo = uer group others# rwx = readable writable executable# +、/ = or, + is deprecated since 2005, use / instead# - = and# = exactly# , = andfind /home -name '*.txt' -perm -o=rw # others: rw | rwxfind /home -name '*.txt' -perm /o=rw # others: r | w | rw | rx | wx | rwxfind /home -name '*.txt' -perm o=rw # others: rwfind /home -name '*.txt' -perm -ugo=rw # uer: rw | rwx # group: rw | rwx # others: rw | rwxfind /home -name '*.txt' -perm ugo=rw # uer: rw # group: rw # others: rwfind /home -name '*.txt' -perm /ugo=rw # invalid mode# 对每个匹配的文件执行指定的命令find /home -exec chmod 777 {} \; # \; 代表命令的结束; {} 代表匹配的文件名(filename match符号)
Tests
| Test |
Description |
| -name pattern |
Match files and directories with the specified wildcard pattern. |
| -iname pattern |
Like the -name test but case-insensitive. |
| -size n |
Match files of size n. |
| -type c |
Match files of type c. |
| -perm mode |
Match files or directories that have permissions set to the specified mode. mode can be expressed by either octal or symbolic notation. |
| -user name |
Match files or directories belonging to user name. The user may be expressed by a username or by a numeric user ID. |
| -group name |
Match file or directories belonging to belonging to group name. name may be expressed may be expressed either as a group name or as a numeric group ID. |
| -nouser |
Match file and directories that do not belong to a valid user. This can be used to find files belonging to deleted accounts or to detect activity by attackers. |
| -nogroup |
Match files and directories that do not belong to a valid group. |
| -empty |
Match empty files and directories. |
| -cmin n |
Match files or directories whose content or attributes were last modified exactly n minutes ago. To specify less than n minutes ago, use -n, and to specify more than n minutes ago, use +n. |
| -cnewer file |
Match files or directories whose contents or attributes were last modified more recently than those of file. |
| -ctime n |
Match files or directories whose contents or attributes were last modified n*24 hours ago. |
| -inum n |
Match files with inode number n. This is helpful for finding all the hard links to a particular inode. |
| -mmin n |
Match files or directories whose contents were last modified n minutes ago. |
| -mtime n |
Match files or directories whose contents were last modified n*24 hours ago. |
| -newer file |
Match files and directories whose contents were modified more recently than the specified file. This is useful when writing shell scripts that perform file backups. Each time you make a backup, update a file (such as a log) and then use find to determine which files have changed since the last update. |
| -samefile name |
Similar to the -inum test. Match files that share the same inode number as file name. |