This question is very common for all shell scripting development and can used in basic commands also. If would like to find the specific word from all the files which is a specific location or different location can use grep command,
grep -rnw '/path/to/destination/' -e 'thelinuxfaq'
-r or -R is recursive,
-n is line number,
-w stands for match the whole word.
-l (lower-case L) can be added to just give the file name of matching files.
-e is the pattern used during the search
-n is line number,
-w stands for match the whole word.
-l (lower-case L) can be added to just give the file name of matching files.
-e is the pattern used during the search
Also can we use along with the options are --exclude, --include, --exclude-dir flags could we used for efficient searching the word with grep command,
If you would like to search through those files (--include) which have extensions like .txt or .sh
grep --include=\*.{txt,sh} -rnw '/path/to/destination/' -e "thelinuxfaq"
would like to search exclude all the files ending with .h extension:
grep --exclude=\*.h -rnw '/path/to/destination/' -e "thelinuxfaq"
It's possible for exclude one or more directories when search the same word. For example the directories will exclude "folder1/, folder2/, and all of the matching with *-doc/"
grep --exclude-dir={folder1,folder2,*-doc} -rnw '/path/to/destination/' -e "thelinuxfaq"
Comments (0)