Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic treesize bash script with du & better defaults
#/bin/sh
#set -x #echo on
if [ "$1" == "-h" ]; then
echo "usage: treesize [depth (0)] [sizelimit (1MB)]"
echo ""
echo "example: treesize 3 20G"
echo ""
echo "Show all folders larger than 20GBs & only scan 3 directories in deep"
echo "defaults are 0 depth, 1MB limit equiv to treesize 0 1MB"
exit
fi
if [ "$1" == "" ]; then
DEPTH="-d0"
else
DEPTH="-d$1"
fi
if [ "$2" == "" ]; then
SIZE="-t1MB"
else
SIZE="-t$2"
fi
du -hx $SIZE $DEPTH * | sort -h;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment