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.
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”.
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).
Add the -v option to your grep command to invert the results.
You can quote the pattern:
grep -r --exclude="*.cmd" "ckim" ./
PS. ./
is the current directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With