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
    5 Ways that CSS and JavaScript Interact That You May Not Know About

    CSS and JavaScript:  the lines seemingly get blurred by each browser release.  They have always done a very different job but in the end they are both front-end technologies so they need do need to work closely.  We have our .js files and our .css, but...

  • By
    Page Visibility API

    One event that's always been lacking within the document is a signal for when the user is looking at a given tab, or another tab. When does the user switch off our site to look at something else? When do they come back?

Incredible Demos

  • By
    Create a 3D Panorama Image with A-Frame

    In the five years I've been at Mozilla I've seen some awesome projects.  Some of them very popular, some of them very niche, but none of them has inspired me the way the MozVR team's work with WebVR and A-Frame project have. A-Frame is a community project...

  • By
    jQuery UI DatePicker:  Disable Specified Days

    One project I'm currently working on requires jQuery. The project also features a datepicker for requesting a visit to their location. jQuery UI's DatePicker plugin was the natural choice and it does a really nice job. One challenge I encountered was the...

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!