grep does not find a way to hide a folder

Source: Internet
Author: User

grep does not find a way to hide a folder

The default grep searches all files, including files under Hidden folders.

For example, use the following command to search for Mediabutton strings, which contain files under hidden folders.

GREP-NR Mediabutton *

If you are using SVN-managed code, there is a. svn hidden folder under each folder that contains control information about the version of the code, and it will accumulate over a large amount of the day. If it's just a default search, a lot of search results are in the SVN directory, which is worthless to us, and it can take a lot of time.

The--exclude-dir= parameter of grep is to exclude a directory, which does not contain the directory after the equals sign, so we can use this parameter to remove the. SVN hidden directory.

The use of the--exclude-dir= parameter is as follows:

1. If you had GNU Grep, it should work like this:

---=". SVN" For example: Find all code with "Mediabutton" string in the current directory and subdirectoriesand print line numbers    

Grep-nr--exclude-dir= ". SVN" Mediabutton *

Or

GREP-NR--EXCLUDE-DIR=\.SVN Mediabutton *

The directories to be excluded after--exclude-dir= are enclosed in double quotation marks or directly to the directory name, but special characters must be represented by an escape character, such as ". SVN".


2.If happen to is on a Unix System without GNU Grep, try the following:

This is done by using a double-layer "filter" of the pipeline, where the second grep uses the- v option, which is the inverse match , which prints out the mismatched rows

-"Whatever"*| -"\.svn/*"3. If you enter the --exclude-dir= parameter each time, is it slow and error prone, reducing efficiency?    

But don't worry, we can add the--exclude-dir= parameter by adding a configuration file  ~/.bashrc  (this is bash's current user profile) to simplify operations and improve efficiency.

Add the following command at the end of the ~/.BASHRC file:

Export grep_options= "--EXCLUDE-DIR=\.SVN"

 then save, execute the source ~/.BASHRC or. ~/.BASHRC to make the changes work. 

Then, when searching, execute the following command:

GREP-NR Mediabutton *

This will load the Grep_options option by default, without searching for the. SVN directory.

Note that the Grep_options keyword can not be modified to other, otherwise the system will not be considered to be GREP an option parameter.


Reference:

http://blog.csdn.net/ameyume/article/details/7711420

grep does not find a way to hide a folder

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.