Last active
October 25, 2015 23:57
-
-
Save stevenvo/6ccbb92ca048d6259900 to your computer and use it in GitHub Desktop.
Search files for specific content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Do the following: | |
grep -rnw '/path/to/somewhere/' -e "pattern" | |
grep --exclude=\*.{o,a,.so} -rnw '.' -e "msse" | |
-r or -R is recursive, -n is line number and -w stands match the whole word. -l (letter L) can be added to have just the file name. | |
Along with these, --exclude or --include parameter could be used for efficient searching. Something like below: | |
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern" | |
This will only search through the files which have .c or .h extensions. Similarly a sample use of --exclude: | |
grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern" | |
Above will exclude searching all the files ending with .o extension. Just like exclude file it's possible to exclude/include directories through --exclude-dir and --include-dir parameter, the following shows how to integrate --exclude-dir: | |
grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern" | |
This works for me very well, to achieve almost the same purpose like yours. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
grep --exclude=*.{o,a,.so} -rnw '.' -e "msse"