sort snippets

How to list and sort directories by size in Linux/Unix

Tagged list, directories, size, du, sort, disk, harddisk, space  Languages bash

For human-readable output use the following command:

du -sh /* | sort -h

Use this command to find the directories taking up the most space:

du -k | sort -nr | more

The du command along with the -k switch lists all directories and their respective size in kilobytes. The sort command sorts the output so that the largest directory is shown first in the list. The -nr switch reverses the list and uses only numbers when sorting.

Here’s an example of the output:

12939451  .
1814892  ./abcdef
1219582  ./abcde
839586  ./abcd
718330  ./abc
695610  ./ab
690380  ./a