Locate Empty Directories from Command Line

By  on  

As a software engineer that lives too much of his life on a computer, I like keeping my machine as clean as possible. I don't keep rogue downloaded files and removes apps when I don't need them. Part of keeping a clean, performant system is removing empty directories.

To identify empty directories, I use the following command:

find . -type d --empty

To remove empty directories, we can add a --delete flag:

find . -type d --empty --delete

Keeping a clean machine is easy when you know the tools that can help you. find makes identifying and eliminating easy, so don't be afraid to use it!

Recent Features

  • By
    How to Create a Twitter Card

    One of my favorite social APIs was the Open Graph API adopted by Facebook.  Adding just a few META tags to each page allowed links to my article to be styled and presented the way I wanted them to, giving me a bit of control...

  • By
    Serving Fonts from CDN

    For maximum performance, we all know we must put our assets on CDN (another domain).  Along with those assets are custom web fonts.  Unfortunately custom web fonts via CDN (or any cross-domain font request) don't work in Firefox or Internet Explorer (correctly so, by spec) though...

Incredible Demos

Discussion

  1. Jim L

    A minor change as it should have a single ‘-‘ on the empty predicate:

    find . -type d -empty

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!