Getting the size of a file

Getting the size of a file

am 09.02.2005 18:49:18 von poochie2DON-T-SPAM

Hi all,

I need a bit of help.
Supposing that in $filename I got a file, how can I put in a variable
its size?

Thanks in advance,

--
Poochie©

Re: Getting the size of a file

am 09.02.2005 19:00:33 von Christian

"Poochie©" a écrit dans le message de
news:1grqcb6.qx4rdtogy5g0N%poochie2DON-T-SPAM@libero.it...
> Hi all,
>
> I need a bit of help.
> Supposing that in $filename I got a file, how can I put in a variable
> its size?
>
> Thanks in advance,
>
> --
> Poochie©

Something like :

size=`ls -la ${filename} | awk '{print $5}'`

C.

Re: Getting the size of a file

am 09.02.2005 19:03:40 von poochie2DON-T-SPAM

Christian wrote:

> Something like :
> size=`ls -la ${filename} | awk '{print $5}'`

Thanks, I'm not that used to awk

--
Poochie©

Re: Getting the size of a file

am 09.02.2005 20:39:50 von Rakesh Sharma

Poochie=A9 wrote:
>
> I need a bit of help.
> Supposing that in $filename I got a file, how can I put in a variable
> its size?
>


filesize=3D`perl -le'print+join"\n",(stat("'"$filename"'"))[7]'`

Or:

filesize=3D`wc -c < $filename`

(but remember to strip the leading spaces with this method)

Re: Getting the size of a file

am 09.02.2005 22:05:20 von William

"Poochie©" wrote in message
news:1grqd0c.1flu2c7wb0hg7N%poochie2DON-T-SPAM@libero.it...
> Christian wrote:
>
> > Something like :
> > size=`ls -la ${filename} | awk '{print $5}'`
>
> Thanks, I'm not that used to awk

If you want to stay inside bourne shell, you could do something like:

set -- `ls -la ${filename} 2>/dev/null` 'X'
sizeOfFile=${5:-0}

The set parses the output of the command into the positional parameters.
On my Solaris system, if the command errors out, it leaves the parameters
set to whatever they were so making sure set has at least one value ('X')
prevents that. If you don't want sizeOfFile set to 0 in case of an error,
you
can simplify it to:

set -- `ls -la ${filename} 2>/dev/null` && sizeOfFile=$5

-Wm

Re: Getting the size of a file

am 09.02.2005 22:13:32 von someone

Rakesh Sharma wrote:
> Poochie© wrote:
>
>>I need a bit of help.
>>Supposing that in $filename I got a file, how can I put in a variable
>>its size?
>
>
> filesize=`perl -le'print+join"\n",(stat("'"$filename"'"))[7]'`

filesize=`perl -e"print -s '$filename'"`



John
--
use Perl;
program
fulfillment

Re: Getting the size of a file

am 10.02.2005 15:33:26 von gazelle

In article <1107977990.443608.154930@z14g2000cwz.googlegroups.com>,
Rakesh Sharma wrote:
....
>
>filesize=3D`perl -le'print+join"\n",(stat("'"$filename"'"))[7]'`
>
>Or:
>
>filesize=3D`wc -c < $filename`
>
>(but remember to strip the leading spaces with this method)
>

And the "3D"s - which are probably only there for artistic reasons.