1. # 匹配文件名字
  2. find -name '*.txt' # 在【当前目录】下【递归】寻找 txt 类型的文件
  3. find /home -name '*.txt' #在【指定的目录】(即/home)下寻找
  4. # 匹配文件大小 单位:bcwkMG
  5. find /home -name '*.txt' -size 100k # 大小为 100k 的 txt 文件
  6. find /home -name '*.txt' +size 100k # 大小大于 100k 的 txt 文件
  7. find /home -name '*.txt' -size 100k # 大小小于 100k 的 txt 文件
  8. # 匹配所属用户
  9. find /home -name '*.txt' -user ronnie # 所有属于 ronnie 的 txt 文件
  10. # 取反
  11. find /home -name '*.txt' -not -user ronnie # 所有不属于 ronnie 的 txt 文件
  12. # 匹配权限
  13. # ugo = uer group others
  14. # rwx = readable writable executable
  15. # +、/ = or, + is deprecated since 2005, use / instead
  16. # - = and
  17. # = exactly
  18. # , = and
  19. find /home -name '*.txt' -perm -o=rw # others: rw | rwx
  20. find /home -name '*.txt' -perm /o=rw # others: r | w | rw | rx | wx | rwx
  21. find /home -name '*.txt' -perm o=rw # others: rw
  22. find /home -name '*.txt' -perm -ugo=rw # uer: rw | rwx
  23. # group: rw | rwx
  24. # others: rw | rwx
  25. find /home -name '*.txt' -perm ugo=rw # uer: rw
  26. # group: rw
  27. # others: rw
  28. find /home -name '*.txt' -perm /ugo=rw # invalid mode
  29. # 对每个匹配的文件执行指定的命令
  30. 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.