I have the given code below for converting bytes to the corresponding values:
for OUTPUT in $(find $IP_DIR -maxdepth 1 | awk 'NR>1')
do
case $RETURNSIZE in
"gb") FS=`du -b $OUTPUT | awk {'print $1'}`
FS=`echo $FS | awk '{ byte =$1 /1024/1024**2 ; print byte " GB" }'`
echo $OUTPUT "|" $FS;;
"mb") FS=`du -b $OUTPUT | awk {'print $1'}`
FS=`echo $FS | awk '{ byte =$1 /1024/1024 ; print byte " MB" }'`
echo $OUTPUT "|" $FS;;
"kb") FS=`du -b $OUTPUT | awk {'print $1'}`
FS=`echo $FS | awk '{ byte =$1 /1024 ; print byte " KB" }'`
echo $OUTPUT "|" $FS;;
"b") FS=`du -b $OUTPUT | awk {'print $1'}`
echo $OUTPUT "|" $FS "B";;
esac
OUTPUT
/home/work/exten.sh | 3.53903e-07 GB
/home/work/e.txt | 0 GB
/home/work/t.txt | 0 GB
/home/worktest | 9.53674e-07 GB
/home/work/s.txt | 3.23169e-07 GB
The logic seems to be perfectly working but when the case comes to gb (RETURNSIZE)
, the result is in exponential format.
But I am looking for the result in normal decimal format.
linux
: what's wrong withdu -Sh
?OFMT
. Or useprintf()
instead ofprint
.