Skip to content

Instantly share code, notes, and snippets.

@elvisciotti
Last active August 14, 2022 06:50
Show Gist options
  • Save elvisciotti/273f2d55aa20fe9cc075042db0e10983 to your computer and use it in GitHub Desktop.
Save elvisciotti/273f2d55aa20fe9cc075042db0e10983 to your computer and use it in GitHub Desktop.
Bash function to display directories from the biggest ones at the top
#/bin/bash
function treesize() {
du -k -d 1 $1 | sort -nr | 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;
}
'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment