On Sat, Jul 26, 2025 at 10:12:35AM -0000, Stuart Henderson wrote: > Other than wc, I think ls -l | awk is probably the most portable way.
That will break badly if you feed it the name of a directory or a device file rather than a regular file. If you're going to use ls -l | awk, then it should probably be ls -ld | awk, to solve at least the directory problem. Device files would still break it, (unless the awk part copes with that). Using wc is also prone to problems in the device file case: $ wc -c /dev/urandom ... will take a while to complete ;-). Stat, despite not necessarily being portable to non-OpenBSD systems, copes better with being given things other than regular files. $ stat -f %z /dev/urandom 0