Find and grep

Source: Internet
Author: User
Find and grep-general Linux technology-Linux programming and kernel information. The following is a detailed description. Find the shell commands for all cpp and H files containing the "Test" string in the current directory (including subdirectories)

Find.-name "*"-exec grep-I "xxxx" {}\;-print

Where-I is the grep parameter, indicating that case sensitivity is ignored

In linux, There is a description in man find:

-Exec command;
Execute command; true if 0 status is returned. All following
Arguments to find are taken to be arguments to the command
An argument consisting of ';' is encountered. The string '{}'
Is replaced by the current file name being processed everywhere
It occurs in the arguments to the command, not just in arguments
Where it is alone, as in some versions of find. Both of these
Constructions might need to be escaped (with a' \ ') or quoted
Protect them from expansion by the shell. The command is exe-
Cuted in the starting directory.

This means that an external command can be called after "FIND". All subsequent parameters are parameters of this command until a parameter consisting of ";" is called. The string "{}" is replaced by the currently being processed file name. "\" Is an escape character.

Example: find.-name "*. php"-exec grep viewnew {}-H \;

This command is used to check all the PHP files in the subdirectories below the current directory, and use GREP to check the files containing "viewnew" and display the file name.

In addition, you must note that you often encounter find: missing argument to '-exec' during use'

This does not mean that there is no exec parameter, but the parameters following exec are incorrect. In this case, check whether there are spaces or the like before.
Related Article

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.