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.
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. :)
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.
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"
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.
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 :
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.
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).
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.
29 comments
[ 2.7 ms ] story [ 54.4 ms ] threadhttps://github.com/daniel-beck/tkdu
https://karl-voit.at/2014/03/25/xdu/
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.
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.
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.
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!
http://www.derlien.com/
https://windirstat.net/
Slightly cleaner solution would be something like
(with appropriate flags)https://www.gnu.org/software/coreutils/manual/html_node/numf...
`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.
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.
https://www.google.com/search?q=ncdu