Delete multiple files/folders in multiple depths

May 27th, 2009 | Tags: , , , , , , ,

I’ve run across the problem every so often where I need to delete a lot of folders at various directory depths on my OS X system. For example, I recently wanted to quickly clear out all my “.svn” folders in a working copy I had. Well, you can’t search hidden folders with Spotlight, so it wasn’t immediately apparent what I should do.

I eventually found this nice solution from a combination of information online, using the command line, of course:

find ./ -name “.svn” | xargs -I {} rm -R “{}”

The “find” command gets all the right folders (good idea to run that alone first to make sure it’s picking up everything you want and ONLY what you want!) and then passes the results to “xargs” which splits its input into multiple arguments by spaces and newlines and passes them as arguments to the given command. In this case, we’re passing them to “rm” which then removes all the “.svn” folders.

  1. July 8th, 2009 at 15:50
    Reply | Quote | #1

    You can also accomplish the same thing with find:

    find ./ -name “.svn” -exec rm -r {} \;