« Home | My Financial Goal for 2009: 100% Debt Free (foreve... » | Apple and Stanford to offer free iPhone developmen... » | 16,906 miles, 4 cities, and 2 more passport stamps... » | Using screen utility to connect to serial devices » | Fix: Running screen under Mac OS X clobbers path » | Fear and loathing » | Regscan = scam (Skype: Windows Requires Immediate ... » | Financial Crisis Made Simple... » | Git: Script to svn rebase subdirectories » | How to force qmake to stop generating an XCode pro... »

How to recursively delete files and directories (*.svn) with find and xargs

Every once in a while, I want to delete some files from a set of directories.  Under windows you do a file search, select everything with CTRL-A and delete.  It is every bit as simple under Linux and OS X. 

For example, let's say you want to tar up or merge directories that are checked out of a subversion repository.  If you just tar up the files, you will have extra copies of every single file making the tarball needlessly large.  Not good.  Or maybe you want to delete those .DS_Store files that OS X craps all over your hard drives.

Here's how to do it.  Use the find command to find the .svn directories and pipe the output to the xargs utilities to merge the output into something the rm command can use.  This can be used to quickly delete other files patterns, but be very careful (for obvious reasons):

   1: rm -rf `find . -name "*.svn" | xargs`

Simple.

Labels: ,