Sunday, October 19, 2014

Search Keyword in a Specific Directory Recursively in Linux

We can search a string recursively in a directory via grep command in linux.

Do the following:

grep -r "word" . In which, -r stands for recursive.

More advanced option:

grep -ril "word" *.log -i means ignore-case;
-l will only show the file name which contains the keyword, without printing the context of the keyword.

grep --exclude=*.txt -r "word" . --exclude will search all the files in current directory whose file name does not match the pattern "*.txt".

grep --include=*.txt -r "word" * Likewise, --include is just the opposite condition of --exclude.


© 2014-2017 jason4zhu.blogspot.com All Rights Reserved 
If transfering, please annotate the origin: Jason4Zhu

1 comment: