1. Introduction
Find Path-option [-print] [-exec-ok command] {} \;
#-print to output the found file to standard output
#-exec command {} \; -– will find the file to execute command operation, {} and \; There are spaces between
#-ok and-exec are the same, except to consult the user before the operation
2, find command options
-name
Find files by file name.
-perm
Locate files by file permissions.
-prune
Use this option to make the Find command not look in the currently specified directory, and if you use the-depth option, then-prune will be ignored by the Find command.
-user
Locate files according to the owner of the file.
-group
Locate the file by the group to which the file belongs.
-mtime-n +n
To find a file by the time the file was changed-n indicates that the file change time is now n days, + n indicates that the file change time is now N days ago. The Find command also has the-atime and-ctime options, but they are all like-mtime options.
-nogroup
Finds a file that does not have a valid owning group, that is, the group that the file belongs to does not exist in/etc/groups.
-nouser
Finds a file without a valid owner, that is, the owner of the file does not exist in/etc/passwd.
-newer file1! File2
The Find change time is newer but older than the file File1 file file2.
-type
Find a type of file, such as:
B-block device files.
D-Directory.
C-Character device files.
P-pipe file.
L-Symbolic link file.
F-Normal files.
-size N:[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes.
-depth: When looking for a file, first look for the files in the current directory and then look in their subdirectories.
-fstype: Find files in a type of file system that can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system.
-mount: Does not cross the file system mount point when locating files.
-follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to.
-cpio: Use the cpio command for matching files to back up these files to a tape device.
In addition, the following three differences:
-amin N
Find the last n minutes of files accessed in the system
-atime N
Find the last n*24 hours accessed in the system
-cmin N
Find files in the system where the last n minutes have been changed file status
-ctime N
Find files in the system with the last n*24 hour changed file status
-mmin N
Find files in the system with the last n minutes of changed file data
-mtime N
Find files in the system for the last n*24 hours changed file data
3. Example
1 The Find command matches all the normal files in the current directory and lists them using the Ls-l command in the-exec option.
# Find. -type f-exec ls-l {} \;
2 in the/logs directory to find the change time before 5th files and delete them
$ find Logs-type f-mtime +5-exec rm {} \;
References: http://www.hackbase.com/tech/2008-04-29/40594.html