Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically ignore files in grep

Tags:

grep

bash

Is there any way I could use grep to ignore some files when searching something, something equivalent to svnignore or gitignore? I usually use something like this when searching source code.

grep -r something * | grep -v ignore_file1 | grep -v ignore_file2

Even if I could set up an alias to grep to ignore these files would be good.

like image 945
rampr Avatar asked Dec 12 '09 04:12

rampr


People also ask

How do I ignore a grep file?

To ignore the case when searching, invoke grep with the -i option. If the search string includes spaces, you need to enclose it in single or double quotation marks. You can use the -e option as many times as you need. Another option to exclude multiple search patterns is to join the patterns using the OR operator | .

Does Git automatically ignore files?

Git can only ignore files that are untracked - files that haven't been committed to the repository, yet. That's why, when you create a new repository, you should also create a . gitignore file with all the file patterns you want to ignore.

How to exclude characters in grep?

The most simple way to exclude lines with a string or syntax match is by using grep and the -v flag. The output will be the example. txt text file but excluding any line that contains a string match with “ThisWord”. Use whichever works best for your particular workflow.


1 Answers

--exclude option on grep will also work:

grep  perl * --exclude=try* --exclude=tk*

This searches for perl in files in the current directory excluding files beginning with try or tk.

like image 62
ennuikiller Avatar answered Sep 23 '22 03:09

ennuikiller