News for hackers. Stuff that matters.
Re:Show HN: Dut, a fast Linux disk usage calculator by INTPenis on Thursday July 11, 2024 @02:56AM (#40934256)
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;
         }
        '
Re:Show HN: Dut, a fast Linux disk usage calculator by mshook on Thursday July 11, 2024 @03:37AM (#40934465)
I don't understand the point of the script, it's nothing more than:

  du -h --max-depth=1 "$@" | sort -hr
Re:Show HN: Dut, a fast Linux disk usage calculator by dotancohen on Thursday July 11, 2024 @04:17AM (#40934630)
The point is that it is faster.
Re:Show HN: Dut, a fast Linux disk usage calculator by zamadatix on Thursday July 11, 2024 @03:11PM (#40939622)
A bash script for postprocessing the sorting is certainly slower than just having sort do it correctly in the first place.
Re:Show HN: Dut, a fast Linux disk usage calculator by out-of-ideas on Thursday July 11, 2024 @03:44AM (#40934499)
`-h` is not available in all `sort` implementations
Re:Show HN: Dut, a fast Linux disk usage calculator by BlackLotus89 on Thursday July 11, 2024 @06:08AM (#40935103)
Even 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
Re:Show HN: Dut, a fast Linux disk usage calculator by out-of-ideas on Thursday July 11, 2024 @08:26PM (#40941780)
i 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

Re:Show HN: Dut, a fast Linux disk usage calculator by INTPenis on Thursday July 11, 2024 @09:41AM (#40936729)
I 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.
Re:Show HN: Dut, a fast Linux disk usage calculator by matzf on Thursday July 11, 2024 @03:38AM (#40934469)
Any particular reason for doing the human readable units "manually"? `du -h | sort -h` works just fine.
Re:Show HN: Dut, a fast Linux disk usage calculator by kelahcim on Friday July 12, 2024 @04:30AM (#40943685)
Nice!
Re:Show HN: Dut, a fast Linux disk usage calculator by kelahcim on Thursday July 11, 2024 @04:43AM (#40934740)
I will definitely try this one and compare with my daily stuff

`du -s -k * | sort -r -n -k1,1 -t" "`