On Wed, Feb 18, 2004 at 10:07:36AM +1300, Sharrea Day wrote:
> Hi
> Does anyone know how to get the size of a file in a bash script?  I want to 
> compress the file with tar when the file size exceeds 10 MB but can't 
> figure out how to do it.
> 
> Still googling... any help much appreciated.

You can probably do it with ls, but I like du (man du). For example

fileToTest=/home/you/growingfile
fileSize=`du -ms $fileToTest | cut -f 1` # discarding file name from
                                         # output
if [ $fileSize -gt 10 ] ;
then
        do something
fi

I wrote a script a while back when I was just starting with bash that
might do what you're looking for (but I'd now use cut instead of calling
awk!): http://clevername.homeip.net/sizetest

HTH,
Todd

Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to