1 Find CommandThe Find command is a ubiquitous command, one of the most useful commands in Linux. The Find command is used to search for files in a directory (and subdirectories), and you can specify matching criteria, such as locating files by file name, file type, user, or even timestamp. Here is an example to experience the power of the Find command.
general form of 1.1 find commandThe general form of the find command given in the man document is:
Find [-h] [l] [P] [D-debugopts] [-olevel] [path ...] [Expression]
In fact [-h] [-l] [p] [D-debugopts] [-olevel] These options are not commonly used and the common form of the Find command above can be simplified to:
Find [path ...] [Expression]
·The directory path that the Path:find command looks for. For example, to represent the current directory, with/to represent the system root directory
·Expression:expression can be divided into--"-options [-print-exec-ok ...]"
-options, specify the common options for the Find command, which is described in detail in the following section
-print, the Find command outputs the matching file to the standard output
-exec, the Find command executes the shell command given by the parameter to the matching file. The form of the corresponding command is
' command ' {} \;, note the spaces between {} and \;
Find ./-size 0-exec rm {} \; Delete files with a file size of zero (you can also do this:
rm-i ' find./-size 0 'Or
Find ./-size 0 | xargs rm-f &)
To list the matching files with the Ls-l command, you can place the Ls-l command in the-exec option of the Find command:
Find .-type f-exec ls-l {} \;
Look for files in the/logs directory that were changed before 5th and delete them:
Find/logs-type f-mtime +5-exec rm {} \;
-okAnd
-execis the same as executing the shell command given by the parameter in a more secure mode, and prompts the user to determine whether to execute it before executing each command.
Find .-name "*.conf"-mtime +5-ok rm {} \; Finds all file names in the current directory to. Log end, change the time in the file above 5th, and delete them, but before deleting the first hint
Others have summed up the structure of the Find command: