#!/usr/bin/ksh ################################################################################ # # Tool to give human-readable output for the '/bin/ls' command. # # Written by Matthew Baker mbaker@computeranddata.com ################################################################################ MYSIZE=$1 if [[ -z $MYSIZE ]] then MYSIZE="-h" fi if [[ -z $(echo $MYSIZE | egrep '\-g|\-m|\-k|\-h') ]] then print "USAGE: $0 [-g|-m|-k|-h)] [ls options] [dirs, files, ...]" print "ERROR:4: must give: -g, -m, -k, -h" exit 4 fi if (( $# )) then shift MYARGS=$* fi # # Humanreadable # if [[ $MYSIZE = "-h" ]] then /usr/bin/ls -al $MYARGS \ | awk '{if ($5 > 1000000000) printf "%10s %3d %-9s %-9s %8.2fG %3s %2s %4s %-s \n", $1 ,$2 ,$3 ,$4 ,(($5/1000000000)) ,$6 ,$7 ,$8 ,$9 else if ($5 > 1000000) printf "%10s %3d %-9s %-9s %8.2fM %3s %2s %4s %-s \n", $1 ,$2 ,$3 ,$4 ,(($5/1000000)) ,$6 ,$7 ,$8 ,$9 else if ($5 > 1000) printf "%10s %3d %-9s %-9s %8.2fK %3s %2s %4s %-s \n", $1 ,$2 ,$3 ,$4 ,(($5/1000)) ,$6 ,$7 ,$8 ,$9 else print $0 }' # # Gigabytes # elif [[ $MYSIZE = "-g" ]] then /usr/bin/ls -al $MYARGS \ | awk '{if ($5 > 1000000000) printf "%10s %3d %-9s %-9s %8.2fG %3s %2s %4s %-s \n", $1 ,$2 ,$3 ,$4 ,(($5/1000000000)) ,$6 ,$7 ,$8 ,$9 else print $0 }' # # Megabytes # elif [[ $MYSIZE = "-m" ]] then /usr/bin/ls -al $MYARGS \ | awk '{if ($5 > 1000000) printf "%10s %3d %-9s %-9s %8.2fM %3s %2s %4s %-s \n", $1 ,$2 ,$3 ,$4 ,(($5/1000000)) ,$6 ,$7 ,$8 ,$9 else print $0 }' # # Kilobytes # else /usr/bin/ls -al $MYARGS \ | awk '{if ($5 > 1000) printf "%10s %3d %-9s %-9s %8.2fK %3s %2s %4s %-s \n", $1 ,$2 ,$3 ,$4 ,(($5/1000)) ,$6 ,$7 ,$8 ,$9 else print $0 }' fi