to get the most granular size of a file, you can do so with:
solaris hosts:
ls -l /tmp/filea | awk '{print $4}'
linux hosts:
ls -l /tmp/filea | awk '{print $5}'
Is there a more universal command that will give the file size?
i'm leery of this ls command because the fields in which the file size can be found differs on sunos and linux, and i'm not even sure if it is also like that with other unix oses.
so, is there a command that can accomplish the above without needing to check a field/column which, for all we know, wont be the same on another unix os.
i've tried "du -s". but that doesn't seem to work across all unix systems.
ok. so it looks like "wc -c" is the answer here? it gives the exact same numbers as "ls -l". difference is, with "wc -c", the file size will always be in the first column. that's perfect! not too sure about the potential overhead though, if there ever is one.
Yes, wc -c is the best answer. It gives the exact correct answer.
As you suggest, do not worry about "overhead" at this point. As you can see from my previous post with the time test, wc runs very fast on large files. If there were really an "overhead" problem, if your script takes too long, you could worry about it then.
Have a 10GB file on an NFS share, and run "wc -c" on it on a hundred NFS clients simultaneously.
This will take very long, and your NFS server will be overloaded the whole time.
And your server admin will be angry. (The redness of his face is proportional to the overhead that you have caused.)
I/O load is normally the file size, unless the file is already cached into RAM.
Time load is measured with time command, using an uncached copy, such as:
$ time wc -c 2011.bb
4234978 2011.bb
real 0m0.009s
user 0m0.000s
sys 0m0.004s
Unless you are dealing with large files, much bigger than the test file above, or you run into a problem, I would not worry about such "overhead" concerns. It's called "premature optimization" to "fix" something by making it complicated, before there is a known problem. On the other hand, if your script is too slow, then time to try something that does not read the actual data on the disk.
Perhaps the script can utilize uname to determine which field to use.
If you can depend on perl availability, then you can use its stat builtin function identically on any platform. A simple example that does not implement any error handling:
find . | perl -lpe '$_ = (stat($_))[7] . "\t$_"'
du was mentioned in several posts. Note that du does not report the file size; it reports the amount of storage that the file occupies. These two values are usually unequal.
This is very strange. On any UNIX System (such as Solaris, HP/UX, OS X, and AIX), the output from the ls -l command should have the file size in the 5th field; not the 4th. Are you using an alias on the Solaris hosts for ls that is employing other options that alter the output? Could you please show us the output of just the ls:
"ls" -l /tmp/filea
on one of your Solaris hosts without feeding it through awk? (Note that I put the ls in quotes to prevent any possible alias substitutions.)
With the amount of space between "root" and the file size, it looks like you might have a group name that is entirely made up of spaces and/or tabs??? Using the l and n options will print user and group numbers instead of names.
Please also show us the output from uname -a on sunbox-01.
You are certainly using /usr/ucb/ls
an old version of ls, only present to provide compatibility with the old SunOS 4, that was terminated 10 years ago (and in turn was compatible with 4.2 BSD Unix).
Use