Posts Tagged ‘grep’

HOWTO: Recursively delete matching files on the Linux command line

Wednesday, October 8th, 2008

An easy way to recursively delete files matching a particular pattern is to use this one liner:

find | grep "search" | perl -nle unlink

UPDATE – Another handy one liner to recursively delete directories is:

rm -rf `find . -type d -name .svn`

Obviously replacing “.svn” with whatever your directories are called.

HOWTO: Recursive search and replace on the Linux command line

Tuesday, September 2nd, 2008

The ‘traditional’ way to search and replace on the command line was to use some combination of grep/find/perl/sed etc. Which offers great flexibility but at the end of the day can turn into a right pain in order to complete a simple task. Turns out only to be a pain in the ass if you don’t know or can’t remember the correct syntax!

Recently I stumbled across rpl. (http://freshmeat.net/projects/rpl/) It’s a nice little text replacement utility which is as simple as:

rpl -R search replace *

Although rpl is easy, the other alternatives are hardly difficult. (At least once you know them)

For non-recursive search and replace try: Perl or sed. (At some point I’m sure I’ll get around to finding recursive Perl and sed alternatives.)