Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep: Excluding a specific folder using

Tags:

linux

grep

Say our folder structure looks like this:

/app
/app/data
...
/app/secondary
/app/secondary/data

I want to recursively search /app/data but I do not want to search /app/secondary/data.

From within the app folder, what would my grep command look like?

like image 548
mattalxndr Avatar asked May 09 '10 21:05

mattalxndr


People also ask

How do I skip a folder using grep?

A directory can be excluded from the grep command search. The --exclude-dir option is used to specify the directory we want to exclude for the grep match.

How do I exclude something in grep?

By default, grep is case-sensitive. This means that the uppercase and lowercase characters are treated as distinct. 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.

How do I exclude a directory in Linux?

Method 1 : Using the option “-prune -o” We can exclude directories by using the help of “path“, “prune“, “o” and “print” switches with find command. The directory “bit” will be excluded from the find search!

What is exclude folder?

If you trust a file, file type, folder, or a process that Windows Security has detected as malicious, you can stop Windows Security from alerting you or blocking the program by adding the file to the exclusions list. Caution: Only do this for files that you're confident are safe.


1 Answers

This will do the trick

grep -r --exclude-dir='secondary/data' PATTERN data
like image 136
seamus Avatar answered Oct 02 '22 05:10

seamus