Thursday, December 6, 2012

How to find which files contain a string in LINUX

Say you want to find which files contain a certain string in linux. Here's how you do it.



find . | xargs grep 'string' -sl


The -s is for summary and won't display warning messages such as grep: ./directory-name: Is a directory
The -l is for list, so we get just the filename and not all instances of the match displayed in the results.

Also useful is, if you want to limit the files to be searched for. 

find . -iname '*.sh' | xargs grep 'string' -sl




No comments:

Post a Comment