Skip to content

Instantly share code, notes, and snippets.

@pilgrim2go
Created April 25, 2017 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pilgrim2go/582bf5ac2d58883a65c8e5973c6d2e8e to your computer and use it in GitHub Desktop.
Save pilgrim2go/582bf5ac2d58883a65c8e5973c6d2e8e to your computer and use it in GitHub Desktop.
Sort disk usage using df command
From: https://lists.gnu.org/archive/html/bug-coreutils/2007-01/msg00131.html
```
df -Pk | tail -n +2 | sort -k3,3n
```
Or if you want to preserve the header, use a script like this:
#!/bin/sh
df -Pk > /tmp/df.$$
(head -1; sort -k3,3n) < /tmp/df.$$
rm -f /tmp/df.$$
@pilgrim2go
Copy link
Author

another way to sort

df -B M | sort -k4 -g # sort by 4th field (Available) numerically
df -B M | sort -k5 -g # sort by 5th field (Use%) numerically

@bakudan-otaku
Copy link

thanks for that, and a little improvement, make it human readable:

df -h | sort -k4 -h # sort by 4th field (Available) human-numeric-sort
df -h | sort -k5 -g # sort by 5th field (Use%) numerically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment