How to list file size on HPUX?

I used to use ls -l cut to detrmine file size, and google searches didn't come up with anything else but 'stat' which doesn't appear on HPUX.
I discovered the humble 'wc -c' which does this job very neatly, and thought I would share it.

Would you consider:-

ls -l file|read perms links owner group size rest
echo $size

This may run faster for larger files as ls reads the directory, where wc will actually read the whole file.

I hope that this helps.
Robin

This is implementation-dependent, many will not.

Perl can be used to invoke stat system call. Refer post

Yes, that's actually the syntax I use. I had been sort of miffed for so long that there wasn't a simple alternative, the discovery of "wc -c" was a bit of a shock.
I'm not sure that "wc -c" will scan the file if it doesn't need to. I guess an experiment will sort that out.
Thanks for the response

I suppose I may well be err-ing on the caution side from normally using wc -l and counting lines, rather than characters. I know that can take a long time, so I just assumed.

I suppose that to assume makes an ass from u and me.

Robin

I just did a test (on HPUX) and "wc -c" does read the whole file. Shame.
I'll keep using Robins syntax :
ls -l | read _ _ _ _ filesize _

3 Likes

Nice idea, variable name _
One comment: this safely works in ksh only.
Not in traditional Unix shells and not in bash - they run the last part of a pipe in a subshell - the variable is not available in the current shell.