0

I typically run the command below to check size on each directory.

du -sBM /* | sort -nr | head -n20

However, specifying a block size of "M" here will give everything a value in "M". The problem with that is once you get below 1M everything reports back as 1M. So this solution is not optimal for me. If I run the command below:

du -sh /* | sort -nr | head -n20

I get the output I really want (block sizes in G,M,and K) but its all out of order. For instance:

618M    /var
387M    /lib
336M    /home
260K    /root
184K    /dev
102M    /boot
32M /etc
32K /tmp
27M /lib64
24K /opt
16K /lost+found
14M /sbin
8.0K    /mnt
7.4M    /bin
4.0K    /srv
4.0K    /net
4.0K    /misc
4.0K    /media
4.0K    /cgroup
2.2G    /usr

I get M's on top of G's and K's on top of M's and so on. I want my output to look like this:

2.2G    /usr
618M    /var
387M    /lib
336M    /home
102M    /boot
32M     /etc
27M     /lib64
14M     /sbin
260K    /root
184K    /dev
32K     /tmp
24K     /opt
16K     /lost+found
8.0K    /mnt
7.4M    /bin
4.0K    /srv
4.0K    /net
4.0K    /misc
4.0K    /media
4.0K    /cgroup

Is there a one-liner here that would do what I want or would a script be a better solution here?

2

Use sort's -h option instead of -n:

du -sh /* | sort -hr | head -n20
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.