Pete's Linux Advent Calendar 2008

The 12th day

Recursively search for a string in text files

You know that grep can search recursively? Either you use the -r switch or ther is a rgrep command on your system. But grep will search also binary files that can mess up your terminal. To only search in text files:
find . -type f -print0 | xargs -0 file | grep '.*:.*text' | cut -d: -f1 | \
    xargs grep "$1"

Pete's Linux Advent Calendar 2008

Valid HTML 4.01!

Comments? send mail to pkruse@arcor.de my monogram