Skip to content

Instantly share code, notes, and snippets.

@jbobbylopez
Last active March 5, 2019 00:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbobbylopez/257f3cbc03cd358e246abf13124ceccd to your computer and use it in GitHub Desktop.
Save jbobbylopez/257f3cbc03cd358e246abf13124ceccd 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