Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 4
    Not necessarily. That might not delete directories with only empty subdirectories. You might have to reverse it. find -type d -print0 | tac | xargs -0 rmdir Commented Sep 11, 2009 at 22:56
  • I never knew about "tac" before. That's really nifty! Commented Sep 12, 2009 at 1:52
  • 1
    Or use find (starting-directory) -depth -type d ....  The -depth option tells find to do something like reverse the order of the output — it goes to the deepest directory levels first, then works its way back up. Commented Jun 21, 2015 at 3:35