Find Empty Files and Directories from Command Line

By  on  

If you are anything like me, you like to keep your projects as tight as possible.  By "tight" I mean no lingering, useless files or directories, because bloat is an incredible annoyance and distraction.  And we don't want distractions, do we?

There's a really easy way to find empty files and directories from the command line:

find /path/to/source/directory -empty

The result will be a list of empty files or directories which you can gloriously remove from your project and relax knowing you're running an incredibly tight ship.

Recent Features

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

  • By
    Chris Coyier’s Favorite CodePen Demos

    David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...

Incredible Demos

  • By
    WebSocket and Socket.IO

    My favorite web technology is quickly becoming the WebSocket API. WebSocket provides a welcomed alternative to the AJAX technologies we've been making use of over the past few years. This new API provides a method to push messages from client to server efficiently...

  • By
    9 Incredible CodePen Demos

    CodePen is a treasure trove of incredible demos harnessing the power of client side languages.   The client side is always limited by what browsers provide us but the creativity and cleverness of developers always pushes the boundaries of what we think the front end can do.  Thanks to CSS...

Discussion

  1. Is this the Mac version of the command? The windows version seems to be in a different order. Plus, I can’t seem to find a setting for the empty folders on Windows. If know, could you share? Thanks.

  2. Arpen

    This command results in f:\>find /path/to/source/directory -empty
    FIND: Invalid switch’ using the command line. Does anyone have a better way to find empty folders using CMD line or Powershell?

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