Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep excluding file name pattern

Tags:

grep

bash

shell

I've read Use grep --exclude/--include syntax to not grep through certain files
but in my CentOS6.4, when I do

grep --exclude=*.cmd ckim * -r 

I see lots of grepped lines from *.cmd files.
so it seems the exclude option is not working for me.
What is wrong?
of course I can do things like

grep ckim \`find . -name \*.c -print\` 

but I want to know why the grep doesn't work.

like image 356
Chan Kim Avatar asked Jul 19 '14 06:07

Chan Kim


People also ask

How do you grep everything except?

How to Exclude a Single Word with 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”.

How will you find all lines in a file which has a pattern A but not pattern B?

The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. The pattern that is searched in the file is referred to as the regular expression (grep stands for global search for regular expression and print out).

How do you invert grep?

Add the -v option to your grep command to invert the results.


1 Answers

You can quote the pattern:

grep -r --exclude="*.cmd"  "ckim" ./ 

PS. ./ is the current directory

like image 96
Tiago Lopo Avatar answered Oct 10 '22 22:10

Tiago Lopo