Skip to content

Commit

Permalink
fixes and modification on the gdu.sh examples
Browse files Browse the repository at this point in the history
different argument handling and fix on space in file names
  • Loading branch information
kakwa committed Nov 10, 2015
1 parent 7398fdd commit 74e0ebe
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions examples/gdu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,7 @@ width=`tput cols`

# simple example to graph the du command output

exit_err(){
msg=$1
printf "$msg\n"
exit 1
}

# default dir to study
dir='./'
# taking all the arguments as one
! [ -z "$@" ] && dir="$@"

# exit if argument is not a directory
[ -e "$dir" ] || exit_err "Directory '$dir' doesn't exist"

# run du -> refomart a little with awk -> give it to asciigraph
du -d 1 "$dir" | \
awk '{printf "%s:%s\n", $2, $1 * 1024;}' | \
du -d 1 $@ | head -n -1 |\
awk '{s = ""; for (i = 2; i <= NF; i++) s = s $i " "; printf "%s:%s\n", s, $1 * 1024;}' | \
asciigraph -l 'Disk Usage' -H -s dec -c -w $width

0 comments on commit 74e0ebe

Please sign in to comment.