Cool Shells and File Operations

5 - `proper' recursive grep

Both rgrep and grep use shell expansion and hence it's difficult to trivially to grep, for instance, all the .cpp files in a source tree.

find . -name '*.cpp' | xargs grep 'GUIObject'

Note the *.cpp is escaped to prevent shell expansion. xargs operates with its argument on every file piped to it.



find is useful for many other things too, for instance if, like me, you have a lot of old object files hanging around:

find . -name '*.o' -exec rm -f '{}' ';'

will recursively find and delete them.


[Next] [Contents]