Powerful and frequently used commands in Linux: Find, Grep__linux

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.