I wonder, what's the best way to determine the size of a file using common unix tools. I need to determine the size of a file in bytes in a shell script. The problem is, that the shell script needs to be portable across different operating systems like osx, irix, linux -- that said: using the "stat" command may not work well, because the arguments required to get the result i want are different on almost every operating system.
I tried to use:
cat ... | wc -c
and while this seems to work quite well, i will probably get issues in a multibyte environment, won't i? So: what's a good way to do this?
For this purpose you can use the following:
I have no idea about its portability. In command's man page it is listed to be in GNU coreutils package.
If you want to determine the size of the file, rather than the space it takes on disk, add --apparent-size.
cksum FILE
From wikipedia
of course the interoperability is mentioned for the checksum and NOT for the counting bytes part.
stat -c %s /path/to/filename
ls
andawk
are pretty standard. You can trywc
doesn't know or care about Unicode -- it thinks a byte is a byte. I also tested this out on a 234 MB .lzma file to proof it... so a simplewc -c
will also get you what you want.