Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to delete all empty folders on an external disk. How can I do this?

share|improve this question
    
Found a simple way to do this: operating-systems.wonderhowto.com/how-to/… –  Vinod Jun 25 '13 at 9:37

1 Answer 1

First of all note that deleting empty directories usually isn't necessary. Some services or applications might even need certain directories to exist. Be aware of what you're doing.

You can list empty folders with find, when run from Terminal.app:

find . -type d -empty

By default find lists files and folders, but here, -type d restricts it to directories, and the -empty option shows only empty directories. This will recurse all folders descending from your home directory (/Users/your-username/ or short, ~). To expand this to your entire filesystem, use:

find / -type d -empty

Here, / signifies the root of your Mac OS X file system. You can of course use any other starting point as well, for example your external disk mounted under /Volumes/your-disk-name;

find /Volumes/your-disk-name -type d -empty

Now, if you want to delete whatever find outputs, simply append -delete, like so:

find . -type d -empty -delete

Note: This will not ask for confirmation. It'll delete all the directories it can, i.e. the ones where you have permissions to delete. They will not be moved to the trash but gone forever. If you want to be asked before removal, change the command to something like the following:

find . -type d -empty -exec rm -ri '{}' \;
share|improve this answer
    
It gives me output about illegal option -- t typeand empty seems to not be able to recognize. –  AsTeR Mar 5 '13 at 12:38
1  
@AsTeR The OS X version of find requires a path, so try again with find . -type d, not find -type d (the latter works for GNU find). –  slhck Mar 5 '13 at 12:43
    
This is amazing. Thank you! –  Simple As Could Be Aug 26 '13 at 23:15
    
fantastic answer. thanks! –  BlackRider yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.