Adam Michael Roach's picture

Delete All Empty Folders from a Directory

Have you ever had a bunch of empty folders in one place that you wanted to get rid of without needing to go through each one first and verify that is empty? The following command will do just that:

WARNING: DO NOT RUN THE FOLLOWING COMMAND AS ROOT UNLESS YOU ARE ABSOLUTELY SURE OF WHAT YOU ARE DOING. THIS COMMAND RESULTs IN A LOSS OF DATA AND MAY NOT BE RECOVERABLE.

find /path/to/scan c -type d -print0 | xargs -0 rmdir --ignore-fail-on-non-empty --parents

Related:

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: [bash], [drupal5], [drupal6], [javascript], [php], [python], [ruby].
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options