Created
November 8, 2016 01:12
-
-
Save zhangchenchen/7d0d9465c4b84c54170f2bec9191fe97 to your computer and use it in GitHub Desktop.
find all files containing specific text on Linux
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
| grep -rnw '/path/to/somewhere/' -e "pattern" | |
| -r or -R is recursive, | |
| -n is line number, and | |
| -w stands match the whole word. | |
| -l (lower-case L) can be added to just give the file name of matching files. | |
| 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. | |
| grep -rnw '/path/to/somewhere/' -e "pattern" | wc -l #get the num of files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment