Unix command to format a number of bytes as a human readable value

It took me a while, but I finally figured out how to print a number from a bash script properly formatted with commas as thousand’s separators. For those like me who weren’t in the know, the magical incantation is:

  printf "%'d" 123456

That will format 123456 as 123,456. Much easier to read when you’re dealing with large numbers such as the sizes of files in gigabytes.

So now if I could only find the Unix command that took a number of bytes and turned it into an approximate value with GB or MB suffixes.

Yo man you are Basic

I’ve been restoring my archives — 10,000,000 files from the past 13 years — and while I did so I had a little bit of a trip down memory lane. I found some old Visual Basic 6 database programs that I wrote when I was in high school, including a phone book, a diary, a time sheeting system, and a few other miscellaneous tools. In order to get them to run I had to get my compiler out to fix a few data object dependencies (DAO5) and a few hardcoded configuration settings such as the paths to database files. So I reinstalled my old VB6 development environment, which I’m pleased to say still works (although I’m still running Windows XP). Good fun. :)