Sorting folders by size

To know about used space of each partition, we usually use df command. See example below:

[bash]df -h[/bash]

And we get a result like this:

In some cases, we’ll add sudo before command to list partitions mounted by others users.

When we need to know about the size of each folder, linux provide us other special program called du.

[bash] du /home/user/some-dir/[/bash]

Such as other programs, du has a lot of arguments and its can combined with other programs like sort.

[bash]du -h[/bash]

Now, to get some folders sorted by size, we can send ‘du -h’ output to sort program:

[bash]du -h | sort -h[/bash]

All folders and sub folders will be printed sorted by their sizes. If you limit by only first depth, you can use –max-depth arg.

[bash]du -h –max-depth=1 | sort -h[/bash]

You’ll get a output like:

:)