sizeup: tidy filesize information in Terminal


This all started with a simple alias:

alias sizes="du -sh * | sort -n"

That outputs all of the file and folder sizes in the current directory, sorted by size, and lists them in human-readable format. Of course, I wanted to make it a more painful endeavor.

Here’s the result. It’s a shell function that will output the file sizes for files (not folders) and provide a total. It accepts file extensions as arguments, and there are flags for controlling sort order and directory traversal depth. Given the lack of real utility, I won’t go into too much depth, other than to say that the __sizeup_build_query and __sizeup_humanize functions are reusable and pretty handy.

To run in the current folder, just use sizeup. Additional options are:

-r	reverse sort
-[0-3]	limit depth (default 4 levels, 0=unlimited)

arguments limit by file extension

Here’s the code that can be added to or sourced by your .*_profile setup.

Ryan Irelan has produced a series of shell trick videos based on posts. Readers can get 10% off using the coupon code TERPSTRA.