Getting the size of a file
am 09.02.2005 18:49:18 von poochie2DON-T-SPAMHi 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©
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©
"Poochie©"
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.
Christian
> Something like :
> size=`ls -la ${filename} | awk '{print $5}'`
Thanks, I'm not that used to awk
--
Poochie©
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)
"Poochie©"
news:1grqd0c.1flu2c7wb0hg7N%poochie2DON-T-SPAM@libero.it...
> Christian
>
> > 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
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
In article <1107977990.443608.154930@z14g2000cwz.googlegroups.com>,
Rakesh Sharma
....
>
>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.