Skip to main content
Tweeted twitter.com/ServerFault/status/658065944510648320

I need to get a list of human readable du output.

However, dudu does not have a "sort by size" option, and piping to "sort"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 -hdu -h by size?

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?

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?

Question Protected by Mark Henderson
Mod Removes Wiki by Mark Henderson
Post Migrated Here from stackoverflow.com (revisions)
Source Link
Tom Feiner
  • 18.7k
  • 8
  • 32
  • 24

How can I sort du -h output by size

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?