Quick ?s
Cheat Sheets
Man Pages
The Lynx

How do I recursively remove empty directories?

Category: Shell Tricks

As usual, there is more than one way to do it. If you have Perl's 'File::Find' module you can do it in a single thread:

perl -MFile::Find -e"finddepth(sub{rmdir},'.')"

Otherwise, you can use find to call rmdir. It just will go through lots of sub-threads and take longer:

find -depth -type d -empty -exec rmdir -v {} \;

Yals.net is © 1999-2009 Crescendo Communications
Sharing tech info on the web for more than a decade!
This page was generated Sat May 2 21:36:42 2009