Monday, 20200127 10:05+1100, Jonathan Gray wrote: > On Sun, Jan 26, 2020 at 11:59:33AM -0500, David Goerger wrote: > > This diff teaches du(1) the -m flag, report disk usage in megabytes. > > This brings us in line with implementations in the other BSDs, Linux, > > and Illumos. > > Why is it needed? -k is required by POSIX, adding arguments for > megabytes, gigabytes, terabytes, petabytes etc seems silly when > there is already 512 byte blocks, kilobytes and -h output.
It's a fair question. My reasoning is two-fold: (1) FreeBSD, NetBSD, Linux, and Illumos all support the "-m" flag, and it's helpful when one can use the same flags/scripts across different systems without surprises. While both FreeBSD and NetBSD also implement "-g" (gigabytes), other systems don't, and it's not an itch I have to scratch. However it's easy to add if we decide we want it. Presently only Linux easily supports blocksizes larger than a gigabyte, via e.g. "-B 1T" as noted by tedu@. FreeBSD also supports "-B", but the argument must be an integer number of bytes[1], e.g. "-B 1099511627776" (1024^4) for 1 terabyte, which is a bit different and feels less natural for everyday use. My feeling is that simple, common, and hard-to-misuse flags like "-m" and "-g" are more useful than an interface which requires most users first open a calculator. (2) We currently support 512-byte (default), kilobyte (-k), arbitrary BLOCKSIZE up to 1g per environ(7), and human-readable (-h), but only the first three can be piped to sort(1) e.g. when investigating filled disk scenarios when one wants to determine the largest files/directories on the disk (human-readable doesn't use the same scale for all outputs, so it can't be sorted as easily). In this case I simply find it easier to conceptualize thousands of megabytes than I do millions of kilobytes. For example: $ BLOCKSIZE=1k du -d0 * | sort -nr | head -n 5 17541678 Audiobooks 9513850 Music 1991678 Documents 1638976 Books 223872 mbox $ BLOCKSIZE=1m du -d0 * | sort -nr | head -n 5 17131 Audiobooks 9291 Music 1945 Documents 1601 Books 219 mbox The environment variable is a bit clunky to pass around and I think a flag like "-m" would represent a nice usability improvement. Thanks! David --- references [1] https://svnweb.freebsd.org/base/head/usr.bin/du/du.c?revision=326025&view=markup#l130
