Topic: https://brettterpstra.com/2019/04/15/sizes-better-disk-usage-reporting-in-terminal/
hide preview

What's next? verify your email address for reply notifications!

unverified 4y, 15d ago

Thanks for this! Found this article after a short Google search on the topic :)

One thing I note is that the file size reported is in Gibibytes — I had to convert to Gigabytes in order to get the figure more commonly shown when hitting CMD + I on a file or directory.

Using this method to play a bit of hard drive tetris and figure out the most space efficient way to store a bunch of large directories across a couple external drives, and this accurate way of getting directory sizes without having to manually CMD + I every directory to get its size is a life saver!

remark link
hide preview

What's next? verify your email address for reply notifications!

Brett 3y, 181d ago

I do have a surprisingly strong google presence for someone who's never made an attempt at SEO… glad it's helpful! I use it all the time myself :).

hide preview

What's next? verify your email address for reply notifications!

unverified 5y, 109d ago

Looks neat. However, when I try it on ruby 2.3.7 I get

/Users/jonathan/bin/sizes:273:indirectory?': no implicit conversion of nil into String (TypeError)`

hide preview

What's next? verify your email address for reply notifications!

Max 5y, 338d ago

Neat. FYI, I hit an error at first, because I was in a directory with a path like /Users/max/Dropbox (Personal)/src/foo/bar. I added an additional call to Shellwords.escape when shelling out to ls and then it worked.

hide preview

What's next? verify your email address for reply notifications!

unverified 5y, 338d ago

I use the following alias:

alias duf='du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done'

Picked it up from http://www.earthinfo.org/linux-disk-usage-sorted-by-size-and-human-readable/ which no longer exists. :-(

remark link
hide preview

What's next? verify your email address for reply notifications!

unverified 5y, 187d ago

How about using the -h option instead of the loop?

 -h      "Human-readable" output.  Use unit suffixes: Byte, Kilobyte, Megabyte, Giga-
         byte, Terabyte and Petabyte.
remark link parent
hide preview

What's next? verify your email address for reply notifications!

unverified 3y, 181d ago

Because then it won't sort -n correctly

hide preview

What's next? verify your email address for reply notifications!