Sorting folders by size

Sorting folders by size

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

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.

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

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

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.

You’ll get a output like:

:)

Linux