The Linux Find command searches the directory structure for files and performs the specified actions. The Find command provides quite a few look-up conditions and is powerful. Because find has powerful features, it has a lot of options, most of which are worth taking the time to look at. Even if the system contains a network file system (NFS), the Find command works equally well in the file system, as long as it has the appropriate permissions. When running a very resource-intensive find command, many people tend to put it in the background because it can take a long time to traverse a large file system (this refers to a file system with more than 30G bytes).
1. Command format
find Pathname-options [-print-exec-ok ...]
2. Command function
used to locate files in the file tree and to make corresponding processing
3. Command parameters
the directory path that the Pathname:find command looks for. For example, use. To represent the current directory, and/to represent the system root directory.
The-print:find command outputs the matched file to standard output.
The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {} \;, note the space between {} and \;
-ok: The same as-exec, except that the shell command given by the parameter is executed in a more secure mode, prompting the user to determine whether to execute before executing each command.
4. Command options
-name Find files by file name.
-perm to find files according to file permissions.
-prune Use this option to have the Find command not be found in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command.
-user Search for files according to the owner of the file.
-group finds files according to the group to which the files belong.
-mtime-n +n The file changes time to find the file,-n means that the file change time is now less than n days, + n means that the file change time is now N days ago. The Find command also has the-atime and-ctime options, but they both and the-m time option.
-nogroup finds a file that does not have a valid owning group, that is, the group to which the file belongs 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 the/etc/passwd.
-newer file1! File2 look for a file that changes time than the file File1 new but older than the file file2.
-type find a file of a certain type, such as:
b -Block device files.
D-Directory.
C-character device file.
P-Pipeline file.
L-Symbolic link file.
F-Normal file.
-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 find the file in the current directory, and then look in its subdirectories.
-fstype: Find files located in a file system of a certain type, these file system types 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 the tape device.
In addition, the following three differences:
-amin N Find the last n minutes of files accessed in the system
-atime Nfind the last n*24 hour Access file in the system
-cmin Nfind files in the last n minutes of the system that have been changed file status
-ctime n Find files that have changed file status in the last n*24 hours of the system
-mmin n Find files that have changed file data in the last N minutes of the system
-mtime n Find files that have changed file data for the last n*24 hours in the system
5. Use Example
Example 1: Finding files that have been modified within a specified time
Command:find-atime-2
Example 2: Search by keyword
Command: Find-name "*.log"
Example 3: Find files by directory or file permissions
Command:find/opt/soft/test/-perm 777
Example 4: Find by Type
Command:find-type f-name "*.log"
Example 5: Find and sort all current directories
Command:find.-type d | sort
Example 6: Find files by size
Command:find.-size +1000c-print
Linux Basic Command (--find) command