Grep search file content

Source: Internet
Author: User
(1) find the findcontents in the file content of all files in the current directory (case insensitive, listing the row of the file where findcontents is located) & mdash; suitable for the current directory, the number of files and directories is relatively small. if too many contents are listed after searching, it will lose...

(1) find the findcontents in the file content of all files in the current directory (case insensitive, listing the row of the file where findcontents is located) -- The number of files and directories in the current directory is relatively small. if too much content is listed after searching, it will lose the meaning of searching.
Grep-rin findcontents *

(2) if too much content is listed after searching, use the following command (only list the number of occurrences of findcontents in the file ):
Grep-ric findcontents * | grep-v: 0

(3) If you do not know the directory where the file is located, you need to search for the entire hard disk space in the root directory ), however, some files (bin, sbin, boot, dev, initrd, and lib) in the root directory have no search value, so they must be excluded from the search scope.
# Cd/
Grep-rin findcontents 'ls | grep-VE' bin | boot | dev | initrd | lib''
------------------------------------------
-I, -- ignore-case
-N, -- line-number
-C, -- count
-R, -- recursive
-V, -- invert-match
-E, -- extended-regexp
-E PATTERN, -- regexp = PATTERN
Use PATTERN as the pattern; useful to protect patterns beginning -.
Note: n becomes invalid when c exists.
 
Find the *. conf file containing the alias string

Find/-name "*. conf" | xargs grep "alias"

1. grep-R-l can also be implemented, but pipeline | is more efficient than simply using grep complex parameters.
2. xargs is used to expand the result obtained by find and use it as the grep parameter.

Author: "Learning linux"

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.