Skip to content

Instantly share code, notes, and snippets.

@sarim
Created May 22, 2013 15:04
Show Gist options
  • Save sarim/5628257 to your computer and use it in GitHub Desktop.
Save sarim/5628257 to your computer and use it in GitHub Desktop.
Pretty Disk Usage
#!/bin/sh
function print_bar {
GDONE=$1
GPROG='['
for i in $(seq 1 1 $GDONE)
do
GPROG=$GPROG'#'
done
GREM=$((30 - $GDONE))
for i in $(seq 1 1 $GREM)
do
GPROG=$GPROG'.'
done
GPROG=$GPROG']'
echo $GPROG
}
VLINES=`df -h | egrep -v '(dev|net|home|Mounted on)'$ | awk '{print $2,"_",$3,"_",$4,"_",$5,"_",$9;}' | sed 's/ _ /_/g'`
for VLINE in $VLINES
do
VCOLS=`echo $VLINE | sed 's/_/ /g'`
VI=0
for VCOL in $VCOLS
do
((VI++))
if [ $VI -eq 1 ] ; then
GCAP=$VCOL
fi
if [ $VI -eq 2 ] ; then
GUSE=$VCOL
fi
if [ $VI -eq 3 ] ; then
GFREE=$VCOL
fi
if [ $VI -eq 4 ] ; then
GPERC=$VCOL
fi
if [ $VI -eq 5 ] ; then
GLBL=$VCOL
fi
done
GPERC=`echo $GPERC | sed 's/%//'`
GPERSCALE=$(( $GPERC * 30 / 100 ))
GBAR=`print_bar $GPERSCALE`
printf "Used %s out of %s\t%s%% %s %s free in %s\n" $GUSE $GCAP $GPERC $GBAR $GFREE $GLBL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment