Skip to content

Color and ‘human readable’ file sizes in Terminal

These are two very old tips, but I'd forgotten about them until recently, when I sent someone a screenshot and they said "Hey, how'd you do that?"

Do what, exactly? This…

The most-obvious thing in that shot is the colored filenames. But notice, too, the file sizes are in a human-readable form. Both of these changes are pretty simple, though you could spend hours playing with colors.

Human-readable output

To get human readable output—not just from ls but also in du, which shows disk space usage—just include an h with the ls command: ls -alh. Instead of raw bytes, the values are converted and marked with trailing B, K, M, etc.

Because I never use ls in its short form, I actually added a line to my .profile (which loads whenever you open a Terminal session) to make this automatic:

alias ls='ls -alh'

You could do the same thing with du, but I rarely use that command, so I didn't bother.

Colorizing ls output

Back in the Mac OS X Hints days, colorizing Terminal's ls output was a popular subject. The nice thing about colorization is you get other benefits: executable files get an asterisk after their names, and directories appear with a trailing slash. So how'd I get colors?

In a nutshell, the color output for ls is managed by two lines in my .profile file:

export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

The first line tells the system to use colors for ls output, and the second line colorizes those lines. How, exactly, is all that mess of letters colors? Many words could be written on that subject, and thankfully, others have written them.

Over at OS X Daily, this post is the one I used for my current dark-background Terminal window—they also have a set for light-colored backgrounds. They also explain how to customize the colors, if you wish—it's not a trivial task, as it's about as anti-GUI as it gets.

There's obviously a lot more you can do to customize Terminal, such as launching sessions with a quote, or changing the look of inactive windows. There's also this slightly old article at OS X Daily with a number of other tips—the tips are still relevant today, though the screenshots are out of date.