Tuesday, May 14, 2013

Find with grep


Need to search a directory tree for files containing a string?  Easy enough with a single file... just use "grep".  Easy enough with all the files in a directory... again, just use grep.


But, if you need to search a whole tree structure... use find, with xargs and grep:

    find . -name *.sh | xargs grep while

This search all files with a .sh extension starting in the current directory for the keyword while

To delete everything in all .svn directories:

    find . -name .svn -print0 | xargs -0 rm -rf

No comments:

Post a Comment