On Wed, 10 Oct 2007, David Korn wrote:

 > > Is there a fast ksh method (builtin, operator, etc.) for getting
 > > the size of a file in bytes?
 > >
 > > I generally use $(wc -c < file) because I think it's more portable than
 > > parsing 'ls' output,
 > > but it's expensive just from the fork&exec alone -- maybe even more
 > > expensive than 'ls'
 > > if wc is actually *counting* bytes as opposed to getting the size from
 > > the i-node.
 > >
 > > But it would sure be handy if I could use something like $(#<file).
 > >
 > > Regards,
 > >   Mario DeFazio
 > >
 >
 > The ast wc command doesn't count bytes with wc -c < file. In addition,
 > you can do
 >      builtin wc
 > to get the libcmd version.
 >
 > However, with ksh93, you can get the file size with mechanisms
 > that are built-in.
 >
 >      function fsize # file
 >      {
 >              command exec 5< $1 5<#((EOF)) # open file and seek to EOF
 >              print -r -- $(5<#)      # output file offset
 >              command exec 5<&-       #close the file
 >      }
 > ...

I think it's still unfortunate that there is no portable** stat(2)
equivalent in ksh93.

** portable, as in, no need to compile/link a special library, or
other extraordinary means; ie, standard builtin.

(sorry, I have to whine about this every so often;  note: Xmas is
approaching...)

-- 
Daniel E. Singer, System Administrator
Dept. of Computer Science, Duke University, Durham NC 27708 USA
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to