3 ms·
Reminds me of someone's script I have been using for over a decade. #/bin/sh du -k --max-depth=1 "$@" | sort -nr | awk ' BEGIN { s
by INTPenis 2y ago
Reminds me of someone's script I have been using for over a decade.
#/bin/sh
du -k --max-depth=1 "$@" | sort -nr | awk '
BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
{
u = 1;
while ($1 >= 1024) {
$1 = $1 / 1024;
u += 1
}
$1 = sprintf("%.1f %s", $1, Units[u]);
print $0;
}
'
- mshook 2y agoI don't understand the point of the script, it's nothing more than: du -h --max-depth=1 "$@" | sort -hr
- out-of-ideas 2y ago`-h` is not available in all `sort` implementations
- BlackLotus89 2y agoEven the busybox port has it. The only sort implementation I know of that doesn't have -h is toybox (I guess older busybox implementations are missing it as well), but I'm using -h for well over a decade and seldom had it missing
- out-of-ideas 2y agoi was actually curious when busybox's sort added it; but didnt search too hard. was certainly easy to see gnu get it in 2009 i think (but even then if the dude setup there bashrc long ago and that func/alias works, likely no reason to change it immediatly) i can say an `BusyBox v1.35.0 (2022-08-01 15:14:44 UTC)` did not have -h; so it having it now is kind of a shock to me (looks like busybox v1.36.1 has it - at least from 2023-06-22) - good too! always frustrating when a dev tries using gnu-args and it blows up and i gotta explain the diff between mac-shell-cmds, gnu, and busybox
- dotancohen 2y agoThe point is that it is faster.
- zamadatix 2y agoA bash script for postprocessing the sorting is certainly slower than just having sort do it correctly in the first place.
- INTPenis 2y agoI found this online a long time ago, and it's been with me across BSD, Macintosh and Linux. So I can't say why it is that way, and I didn't know about sort -h before today.
- matzf 2y agoAny particular reason for doing the human readable units "manually"? `du -h | sort -h` works just fine.
- kelahcim 2y agoNice!
- kelahcim 2y agoI will definitely try this one and compare with my daily stuff `du -s -k * | sort -r -n -k1,1 -t" "`