[plug] bash script program help

Cameron Patrick cameron at patrick.wattle.id.au
Wed Jan 11 09:01:34 WST 2006


Russell Steicke wrote:

> On Wed, Jan 11, 2006 at 08:29:10AM +0800, Jon  Miller wrote:
> > I could use some help in creating a program for a task that I need
> > to do.  I would like to know if there is a function in bash
> > scripting or that can be used in a bash script that can determine
> > the size of a file.
> 
> I don't think this is built in to bash, but:
> 
>   function filesize() {
>     echo $(ls -l $1 | awk '{print $5}')
>   }

This can be done more directly using stat(1), e.g.

    filesize () {
        stat -c %s $1
    }

This seems to be slightly Linux-specific, though: it's there on *BSD but
it isn't present on Solaris or Tru64.

Cameron




More information about the plug mailing list