Subject: Re: [ast-users] getting the size of a file
--------

> 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
        }

You should be able to use {var} instead of 5 so that the shell would
pick the file descriptor, but unfortunately there are a couple of
bugs that cause this to fail.

These will be fixed in the next release.

David Korn
[EMAIL PROTECTED]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to