List Files in Human Readable Format

By  on  

I maintain an older computer with a small hard drive.  I use it mostly for storing MP3s, videos, and other types of basic media.  Unfortunately I often get warnings that disk space is low and so I need to delete files I no longer need; i.e. music or movies I have probably grown tired of.  I always sort them by size, largest first, so I can find out where the cogs are.

The problem is I try to stick to command line but only know how to do that sorting with human readable format by using Mac's Finder utility.  I recent found a command which will output the contents of the current directory and its subdirectories by human readable size:

du -sk -- * | sort -n | perl -pe '@SI=qw(K M G T P); s:^(\d+?)((\d\d\d)*)\s:$1." ".$SI[((length $2)/3)]."\t":e'

That command is kinda gross so you'll probably want to save it as an alias.  Nonetheless I now know how to get the desired information from command line!

Recent Features

  • By
    How I Stopped WordPress Comment Spam

    I love almost every part of being a tech blogger:  learning, preaching, bantering, researching.  The one part about blogging that I absolutely loathe:  dealing with SPAM comments.  For the past two years, my blog has registered 8,000+ SPAM comments per day.  PER DAY.  Bloating my database...

  • By
    LightFace:  Facebook Lightbox for MooTools

    One of the web components I've always loved has been Facebook's modal dialog.  This "lightbox" isn't like others:  no dark overlay, no obnoxious animating to size, and it doesn't try to do "too much."  With Facebook's dialog in mind, I've created LightFace:  a Facebook lightbox...

Incredible Demos

  • By
    MooTools Accordion: Mouseover Style

    Everyone loves the MooTools Accordion plugin but I get a lot of requests from readers asking me how to make each accordion item open when the user hovers over the item instead of making the user click. You have two options: hack the original plugin...

  • By
    iPhone-Style Passwords Using MooTools PassShark

    Every once in a while I come across a plugin that blows me out of the water and the most recent culprit is PassShark: a MooTools plugin that duplicates the iPhone's method of showing/hiding the last character in a password field. This gem of...

Discussion

  1. Han

    I use omnidisksweeper once in a while to get rid of junk

  2. Ayman Rady

    I don’t know if this is cross-platform or not, but on Ubuntu I use this

    # -h -- for human readable sizes
    du -sh ./* | sort -h
    

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