See Sizes in Human Readable Format from the Command Line

Jan 25, 2012 - 2 Comments

Human readable output

The default behavior for most command line tools is to show sizes in bytes, for tiny text files that is fine but when you start working with larger items this becomes difficult to read and interpret. The solutions is fairly simple, pass a “human readable” flag with the command, which will convert bytes to a much more meaningful human readable format of kilobytes (kb) , megabytes (mb) , and gigabytes (gb).


This trick applies to basically any modern command line environment, whether in Mac OS X, Linux, BSD, or otherwise.

Show ls, df, du Command Size Results in Human Readable Format

Generally, seeing things as human readable is just a matter of passing an -h flag along with the command.

Three prominent examples are with ls, du, and df:

ls -lh

df -h

du -h

Read on for some specifics about each:

ls – for the generic list command, you’ll need to attach -h to another flag, like -l:

ls -lh

human readable ls output

df – displaying free disk space with df is infinitely more useful when viewed as human readable. While you can also use a lowercase -h the uppercase is even better on the eyes:

df -H

Human readable df output

du – displaying disk usage for a specific file, folder, directory, or whatever, is made easier to interpret with -h

du -sh */

Human readable du output

Check out more tips and things you can do with the command line.

.

Related articles:

Posted by: William Pearson in Command Line, Tips & Tricks

2 Comments

» Comments RSS Feed

  1. Roger Rodgers says:

    I was secretly hoping there would be a universal setting somewhere, but alas there isn’t. I ended up making aliases:

    alias lh=’ls -lh’

    etc

  2. Chris Wanja says:

    Alternative way for listing the disk used for the current working directory (du) would be:

    du -d 1 -h

    The -d flag sets the depth – 1 is the current working directory (command ‘pwd’).

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site