2

Using the find command, it is easy to recursively delete all empty directories. Which empty directories are safe to delete, and which ones are not?

5
  • 7
    Are you thinking about starting from /? Because if so, don't do that. Commented Oct 3, 2013 at 17:15
  • 2
    Doing this indiscriminately sounds like a great way to hose your system.
    – Nanzikambe
    Commented Oct 3, 2013 at 17:30
  • Why would you need to do this? Commented Oct 3, 2013 at 18:27
  • 1
    Just trying to keep a tidy filesystem
    – Demi
    Commented Oct 4, 2013 at 0:00
  • 5
    There are typically hundreds of empty directories on a Linux system because most software saves code and time by assuming the existence of most directories, which is pretty standardized. The only directories typically tested for existence before using are those created by the program. Doing what you propose will hose your system. Take it from someone who's done it... Commented Oct 10, 2013 at 21:24

1 Answer 1

1

You can recursively delete directories in which you put your data (like Documents, Videos, Images, Downloads, etc.), the others into your home directory (e.g. .cache, .gnome, , .ssh), your root, its sub-folders, etc., shouldn't be removed in this way!

A useful and quite safe way to do this is using the rmdir command (with find):

find . -empty -type d -exec rmdir {} +

It starts in the current working directory.

1
  • I certainly was only planning to remove empty directories.
    – Demi
    Commented Oct 16, 2013 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .