Last active
September 20, 2024 23:52
-
-
Save zatricky/41eeb49a22391303f74e2e8e30e24f33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
set -e | |
set -u | |
#set -x | |
diskusage () { # (directory) | |
pushd "$@" > /dev/null | |
echo "## $(pwd) ##" | |
du -xk --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; | |
} | |
' | |
popd > /dev/null | |
} | |
if [ $# -gt 0 ] | |
then | |
counter=0 | |
for i in "$@" ; do | |
let counter++ || true | |
if [ -d "$i" ] ; then | |
diskusage "$i" | |
else | |
echo "Path $i does not exist!" | |
fi | |
[ $counter -lt $# ] && echo || true | |
done | |
else | |
diskusage . | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment