News for hackers. Stuff that matters.
Re:Sort of handy by zokier on Thursday May 21, 2020 @04:16AM (#23255996)
Pretty great example on how the unix pipeline of strings falls apart because the data is so constrained by formatting.

Slightly cleaner solution would be something like

    du | sort | numfmt
(with appropriate flags)

https://www.gnu.org/software/coreutils/manual/html_node/numf...

Re:Sort of handy by paedubucher on Thursday May 21, 2020 @05:43AM (#23256505)
It's not the pipeline that falls apart, it's the formatting of data that is applied too early in the process. Report the sizes numerically in the same unit, sort them numerically, and then format the numbers in a human readable fashion.

`sort -h` is only needed because `du -h` is used in the first place. I admit that `du -h` comes in handy often, it is better not used for further processing.

Your proposed approach is not only more Unix-like, but also does not require bloated implementations of `du` and `sort` capable of parsing human-readable size indications.

Re:Sort of handy by michaelcampbell on Thursday May 21, 2020 @06:05AM (#23256635)
> I admit that `du -h` comes in handy often, it is better not used for further processing.

I'd posit that once you use -h or equivalent, any further processing by a NON-HUMAN that works the way you want is a lucky side effect.

Re:Sort of handy by renox on Friday May 22, 2020 @04:28PM (#23276569)
Nice but somehow I feel that PowerShell users aren't impressed..
Re:Sort of handy by markrages on Thursday May 21, 2020 @01:07AM (#23255002)
Thanks for posting this. My knowledge of "sort" predates this switch.

I wish there was a common command-line tool for "where did all my space go?" It could look at file and directory sizes and modification times, and list the most likely suspects.

Re:Sort of handy by LeoPanthera on Thursday May 21, 2020 @03:17AM (#23255673)
I always use this construction for "where did my space go":

du -ha ~ | sort -hr | head -n 12

-a is the important bit, it recurses down through every directory.

Replace ~ with / or whatever directory you want.

Re:Sort of handy by Scaevolus on Thursday May 21, 2020 @04:59AM (#23256262)

    -a, --all
        write counts for all files, not just directories
Re:Sort of handy by hibbelig on Thursday May 21, 2020 @08:15AM (#23257468)
I like ncdu.
Re:Sort of handy by dnpp123 on Thursday May 21, 2020 @08:58AM (#23257809)
I prefer https://github.com/bootandy/dust , more lightweight
Re:Sort of handy by markrages on Thursday May 21, 2020 @04:16PM (#23264474)
I prefer http://fsv.sourceforge.net/, more heavyweight.
Re:Sort of handy by snt on Thursday May 21, 2020 @03:18AM (#23255676)
I've actually found the output faster to parse if it's all in consistent units (megabytes [-m]). Also find adding a grand total [-c] and staying on one filesystem [-x] useful. I.e. in ~/.bashrc:

  alias dua="du -cmx --max-depth=1"
  alias duas="du -cmx --max-depth=1 | sort -g"
Re:Sort of handy by xalava on Thursday May 21, 2020 @06:10AM (#23256665)
While this is interesting, it illustrates the time and tinkering necessary to combine different tools and documentations to achieve something simple. Another similar example that I use regularly on constrained machines to list installed packages :

   dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | grep -v deinstall | sort -n | awk '{print $1" "$2}'
I wish there were a shell with visual help to build such commands. Meanwhile I slowly add useful combinations as aliases in .*rc And probably use "Disk Usage Analyser" (baobab) for this.
Re:Sort of handy by alanbernstein on Thursday May 21, 2020 @01:36AM (#23255149)
I have essentially this command aliased as the silly sounding "dush1", i.e. disk usage, sorted, human.
Re:Sort of handy by BruceEel on Thursday May 21, 2020 @01:57AM (#23255259)
Yep, nice and handy! You can sort of get 'spoiled' learning command line tools & their options on Linux first...

Perhaps my most infuriating run-in with UNIX ever has been having to use AIX for the first time and dealing with non-GNU du, find, grep, etc.. oh my.

Re:Sort of handy by tecleandor on Thursday May 21, 2020 @02:08AM (#23255332)
Yep. And of course... 'killall'. If you come from GNU/Linux, never use that unless you've read the man page :D

Linux: "killall sends a signal to all processes running any of the specified commands."

AIX: "The killall command cancels all processes that you started"

So, if you're root... good riddance to your system!

Re:Sort of handy by taneq on Thursday May 21, 2020 @01:03AM (#23254970)
Nice update to ol' faithful 'du | sort -n'. Likewise I don't feel too bad for not knowing about sort -h since it was added many years after I regularly used Linux. :)
Re:Sort of handy by skered on Thursday May 21, 2020 @12:32AM (#23254820)
There's always ncdu
Re:Sort of handy by LeoPanthera on Thursday May 21, 2020 @03:20AM (#23255685)
And tkdu, which is abandoned, but still works great. You can pipe the output of du into it, which is useful if you want to visualize a remote server.

https://github.com/daniel-beck/tkdu

Re:Sort of handy by deathanatos on Thursday May 21, 2020 @02:09AM (#23255338)
And the great thing about ncdu is that you won't have to traverse the filesystem again and again as you narrow down where the disk is going, if you don't already have a good guess.
Re:Sort of handy by philsnow on Thursday May 21, 2020 @04:45AM (#23256176)
Re:Sort of handy by juped on Thursday May 21, 2020 @06:42AM (#23256845)
To be honest, I would have just patched sorting into du before looking for a way to do it with pipes. Maybe not GNU du (GNU code and I don't get along well).
Re:Sort of handy by gumby on Thursday May 21, 2020 @02:31PM (#23262775)
My hardcore Unix friends have been complaining since forever that the gnu commands are too fat with too many options but this is precisely why I use them.
Re:Sort of handy by sneak on Thursday May 21, 2020 @04:10AM (#23255947)
Mac GUI alternative (I use both this and du in different circumstances):

http://www.derlien.com/

Re:Sort of handy by forgotmypw17 on Thursday May 21, 2020 @04:52AM (#23256227)
Re:Sort of handy by chrisweekly on Thursday May 21, 2020 @09:12AM (#23257909)
MacOS GUI - I used to use DiskInventoryX, then found GrandPerspective which has met my modest needs for years.
Re:Sort of handy by forgotmypw17 on Thursday May 21, 2020 @04:50AM (#23256217)
I'll just leave this here:

https://www.google.com/search?q=ncdu

Re:Sort of handy by michaelcampbell on Thursday May 21, 2020 @06:07AM (#23256651)
Yeah, don't. Please leave links to actual things.