I need to get a list of human readable du output.
However, du
does not have a "sort by size" option, and piping to sort
doesn't work with the human readable flag.
For example, running:
du | sort -n -r
Outputs a sorted disk usage by size (descending):
du |sort -n -r
65108 .
61508 ./dir3
2056 ./dir4
1032 ./dir1
508 ./dir2
However, running it with the human readable flag, does not sort properly:
du -h | sort -n -r
508K ./dir2
64M .
61M ./dir3
2.1M ./dir4
1.1M ./dir1
Does anyone know of a way to sort du -h
by size?
du
but add the -h to thesort
command. You can add-rh
so the largest are first in the file, otherwise you needtail
to see the space hogs.ncdu
).