For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > June 2004 > scripting question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author scripting question
Robert Smith

2004-05-24, 7:32 pm

Scripting question:
How would I go about checking the size of a file in directory and storing
the size in a variable to use later?


joe@invalid.address

2004-05-24, 7:32 pm

"Robert Smith" <none@none.com> writes:

> Scripting question:
> How would I go about checking the size of a file in directory and
> storing the size in a variable to use later?


If you have the stat command I would use that. If not, you'd have to
parse the output of ls -l, or whatever relevant /proc variable your
system might have.

Joe
--
"Surprise me"
- Yogi Berra when asked where he wanted to be buried.
Jem Berkes

2004-05-25, 1:36 am

>> Scripting question:
>
> If you have the stat command I would use that. If not, you'd have to
> parse the output of ls -l, or whatever relevant /proc variable your
> system might have.


I like using wc -c

--
Jem Berkes
http://www.sysdesign.ca/
Elie De Brauwer

2004-06-08, 3:58 pm

On Mon, 24 May 2004 22:57:49 +0000, joe wrote:

> "Robert Smith" <none@none.com> writes:
>
>
> If you have the stat command I would use that. If not, you'd have to
> parse the output of ls -l, or whatever relevant /proc variable your
> system might have.
>
> Joe


Or you could use du and sed ...

helios@qntal:~$ FILENAME=test.cpp
helios@qntal:~$ SIZE=`du -b $FILENAME | sed 's/[ \t].*//'`
helios@qntal:~$ echo $SIZE
394




--
Elie De Brauwer
http://www.de-brauwer.be

No animals were hurt and no microsoft products were used during the
creation of this e-mail

joe@invalid.address

2004-06-08, 3:58 pm

Jem Berkes <jb@users.pc9.org> writes:

>
> I like using wc -c


If it's a small file, that's fine.

Joe
--
"Surprise me"
- Yogi Berra when asked where he wanted to be buried.
joe@invalid.address

2004-06-08, 3:58 pm

Elie De Brauwer <elie@N0SP4Mde-brauwer.beN0SP4M> writes:

> On Mon, 24 May 2004 22:57:49 +0000, joe wrote:
>
>
> Or you could use du and sed ...


du tells you about disk blocks, which isn't necessarily the same thing
as file size.

Joe
--
"Surprise me"
- Yogi Berra when asked where he wanted to be buried.
Elie De Brauwer

2004-06-08, 3:58 pm

On Tue, 25 May 2004 05:34:02 +0000, joe wrote:

> Elie De Brauwer <elie@N0SP4Mde-brauwer.beN0SP4M> writes:
>
>
> du tells you about disk blocks, which isn't necessarily the same thing
> as file size.
>
> Joe


that is why I was using du -b instead of du

helios@qntal:~$ echo "test" > testfile.txt
helios@qntal:~$ du -b testfile.txt
5 testfile.txt

helios@qntal:~$ hexdump testfile.txt
0000000 6574 7473 000a
0000005

greetings



--
Elie De Brauwer
http://www.de-brauwer.be

No animals were hurt and no microsoft products were used during the
creation of this e-mail

Villy Kruse

2004-06-08, 3:58 pm

On Tue, 25 May 2004 06:02:07 GMT,
Elie De Brauwer <elie@N0SP4Mde-brauwer.beN0SP4M> wrote:


> On Tue, 25 May 2004 05:34:02 +0000, joe wrote:
>


>
> that is why I was using du -b instead of du
>


May not be that portable

$ ls -l abcc
-rwxrwxr-x 1 xxx xxx 21 May 25 09:35 abcc
$ du -b abcc
1024 abcc
$ du abcc
1 abcc


Villy
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com