PDA

View Full Version : Terminal Command to Recursively Delete all Empty Folders



decryption
9th October 2007, 03:26 PM
As simple as the topic states: I want a terminal command that will go through a folder and it's sub-folders and remove any folder that is empty.

Can anyone help?

conufsed
9th October 2007, 03:35 PM
Something along the lines of


find <basepath> -empty | xargs rmdirshould be your freind

marc
9th October 2007, 04:15 PM
Dangerous!

Let us know how you go. I have some install DVDs here for you if you botch it ;)

Jedda
9th October 2007, 05:23 PM
Your files dont matter Anthony.

Just run rm -r on your root directory.

coljac
9th October 2007, 06:03 PM
I believe we got that sorted out with


find -depth -type d -empty -exec rmdir {}

Or something similar?

decryption
9th October 2007, 08:46 PM
I actually ended up using:


find /Volumes/Music/Music/* -empty -type d | grep -v HFSExtentTables | xargs -I{} rmdir {}

As HFSExtentTables is an empty folder and it shouldn't be deleted :p