Monday, May 31, 2010

How to locate all the files recursively which is having a specific pattern?

find / -type f -exec grep -H 'pattern' {} \;

find . -name 'pattern'

For files containing a specific pattern, you can use grep with -r option.

eg. grep -r 'pattern' *

To find all files which contain "pattern"

find . -type f -print0 | xargs -0 grep -l "pattern"

find ./ -iname '*substring*'

grep -r "pattern" /

the above command will look for the pattern from root directory. Other wise you can mention the path from where you want to search.

find . -name "*pattern*" -exec grep -l otherpattern {} +

With the plus, grep will be given as many filenames as the system can handle rather than one file at a time, reducing the number of instances of gre

No comments:

Post a Comment