Skip to content

Instantly share code, notes, and snippets.

@erselbey
Forked from jbobbylopez/dux.bash
Created March 5, 2019 00:53
Show Gist options
  • Save erselbey/8c23b27bf66c95e16370a58ab3bfef69 to your computer and use it in GitHub Desktop.
Save erselbey/8c23b27bf66c95e16370a58ab3bfef69 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Building extended du reports for $1 in $2 ...";
cd $1
du -sh $1/* $1/.[a-zA-Z0-9]* $1/. > $2/du-output.txt
cat $2/du-output.txt | egrep '([0-9]M)' > $2/du-output-MB.txt
cat $2/du-output.txt | egrep '[0-9]G'> $2/du-output-GB.txt
cat $2/du-output-MB.txt | sort -hr > $2/du-output-MB-sorted.txt
cat $2/du-output-GB.txt | sort -hr > $2/du-output-GB-sorted.txt
echo ""
echo '[du extended report]:';
cat $2/du-output-GB-sorted.txt
GBTOTAL=`cat $2/du-output-GB-sorted.txt | perl -pe 's/^(\d+\.+\d+|\d+)\w*.*/$1/g' | paste -sd+ | bc`
echo -ne "GB Total: $GBTOTAL"
echo ""
echo ""
cat $2/du-output-MB-sorted.txt
MBTOTAL=`cat $2/du-output-MB-sorted.txt | perl -pe 's/^(\d+\.+\d+|\d+)\w*.*/$1/g' | paste -sd+ | bc`
echo "MB Total: $MBTOTAL"
echo ""
FULLTOTAL=`echo "scale=2; ($MBTOTAL / 1024) + $GBTOTAL" | bc`
echo "Full Total (GB): $FULLTOTAL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment