Skip to content

Instantly share code, notes, and snippets.

@draeath
Last active August 23, 2022 23:59
Show Gist options
  • Save draeath/69e915f548f5de5da6eca7e7b1033e82 to your computer and use it in GitHub Desktop.
Save draeath/69e915f548f5de5da6eca7e7b1033e82 to your computer and use it in GitHub Desktop.
sorted disk usage in human readable units (bash)
#!/bin/bash
echo Results for: $(hostname):$(pwd) > ~/du_sorted.txt
sudo nice du -xk --exclude=.snapshot | nice sort -nr | nice \
awk 'BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
{
u = 1;
while ($1 >= 1024) {
$1 = $1 / 1024;
u += 1
}
$1 = sprintf("%.1f %s", $1, Units[u]);
print $0;
}' >> ~/du_sorted.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment