Skip to content
Browse files

modernize disk-usage script; rely on -h presence

  • Loading branch information...
1 parent 48c22bd commit e1acb8f548927f3526c5ba2c552df658b4dfcbf3 Suraj N. Kurapati committed Oct 24, 2012
Showing with 10 additions and 13 deletions.
  1. +10 −13 bin/disk-usage
View
23 bin/disk-usage
@@ -11,23 +11,20 @@
#--
# Written in 2004 by Suraj N. Kurapati
-if [ $# -eq 0 ] ; then
+if test $# -eq 0; then
set -- .* * # default argument is all files in pwd
shift 2 # remove . and ..
fi
usage_file=$(mktemp)
+trap "rm -f $usage_file" EXIT
-if du -sh "${@}" | tee /dev/tty > "$usage_file" 2> /dev/null; then
- echo '----------------------------------------' > /dev/tty
+# preview output while capturing it
+echo '---BEGIN-PREVIEW---' > /dev/tty
+du -hs "${@}" 2>&1 | tee /dev/tty > "$usage_file"
+echo '----END-PREVIEW----' > /dev/tty
- # display units in increasing order
- for unit in $'\t' '[Kk]' '[Mm]' '[Gg]'; do
- grep "^[0-9\.]*$unit" "$usage_file" | sort -n
- done
-
- # clean up
- rm -f $usage_file
-else
- du -s "${@}" | sort -n
-fi
+# display units in increasing order
+for unit in '\s' '[Kk]' '[Mm]' '[Gg]'; do
+ grep "^[0-9\.]\+$unit" "$usage_file" | sort -n
+done

0 comments on commit e1acb8f

Please sign in to comment.
Something went wrong with that request. Please try again.