Skip to content

Instantly share code, notes, and snippets.

@jesse1981
Created July 19, 2013 07:18
Show Gist options
  • Save jesse1981/6037289 to your computer and use it in GitHub Desktop.
Save jesse1981/6037289 to your computer and use it in GitHub Desktop.
Bash Script for viewing folder sizes. Just put this code into a file /bin/treesize and make it executable. Then any system user can get a list of directory sizes within a directory by just running treesize from any directory.
#/bin/sh
du -k --max-depth=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;
}
'
@lonesomewalker
Copy link

Interesting, but not your source, right?

@jesse1981
Copy link
Author

jesse1981 commented Aug 16, 2021

Correct, I believe the original credit goes to Andrew: https://blog.aclarke.eu/2011/09/21/a-simple-treesize-shell-script-for-linux/

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