Find and find Functions
Syntax: find [path] [parameter] [action]
- -Name filename: Find the file named filename.
- -Iname filename: searches for the file named filename, but it is case insensitive.
- -User username: searches for files whose owner is username.
- -Group groupname: Find the file whose group is groupname.
- -Nogroup: Find the file with no valid group, that is, the file group does not exist in/etc/groups.
- -Nouser: Find the file with no valid owner, that is, the file owner is not stored in/etc/passwd.
- -Uid: search by uid
- -Gid: search by gid
- -Mtime + n/-n: file with a write time greater than/less than n days
- -Mmin + n/-n: a file with a write time greater than/less than n minutes
- -Atime + n/-n: access or file execution time greater than/less than n days
- -Amin + n/-n: access or file execution time greater than/less than n minutes
- -Ctime + n/-n: files whose inode attributes (such as owner, permission, or link) are written or modified at a time greater than/less than n days
- -Cmin + n/-n: files whose inode attributes (such as owner, permission, or link) are written or modified at a time greater than/less than n minutes
- -Type B/d/c/p/l/f/s: block device, directory, character device, pipeline, symbolic link, common file, socket File
- -Size + n/-n [bmc], search by file size
- -Perm: search by execution permission
- -Prune: ignore a directory.
- -A connects two different conditions, but both conditions must be met at the same time.
- -O connects two different conditions, and one of the two conditions can be satisfied.
- -Not: returns the inverse of the condition.
Example:
-Perm
# Find/tmp-perm 755 // find the file whose permission is 755 in the/tmp directory
# Find/tmp-perm + 222 // indicates that only the write permission of a user (owner, group, or other) can be matched.
# Find/tmp-perm-222 // indicates that all types of users must have the write permission.
-Size
# Find/tmp-size 2 M // find the file that is equal to 2 M in the/tmp directory
# Find/tmp-size + 2 M // search for files larger than 2 M in the/tmp directory # find/tmp-size-2 M // search for files smaller than 2 M in the/tmp directory file
Find the executed action
#-Print // default action
#-Ls // use ls to display it after searching
#-OK [commend] // query whether the user wants to execute the command after the command is executed
#-Exec [commend] // run the command directly without asking the user when executing the command after searching
# Find/tmp-atime + 30-exec rm-rf {}\;#{} indicates the found File
# Find/tmp-name "*. php" | xargs chmod a + x
Specify multiple directories
# Find/etc/tmp/root-name passwd // directories are separated by Spaces
Use wildcards
*, 0 or multiple arbitrary characters
?, Any character
[], Any character in the brackets
-A,-o,-not
#find /tmp -name "*.php" -a -user root
#find /tmp -name "*.sql" -o user zhaoyn
#find /tmp -not -user root
Ignore specified directory
#find ./ -path "./server" -prune -o -name "*.log" -print
Ignore multiple directories
#find ./ \( -path "./server" -o -path "./test" \) -prune -o -name "*.log" -print