On 2002-05-19 02:13, Alfred Perlstein wrote:
> * Bakul Shah <[EMAIL PROTECTED]> [020519 00:30] wrote:
> > > $ stat -a stat
> >
> > Oops!  A few lines got eaten!
> >
> > $ stat -a stat
> > May 19 00:24:42 2002|48|May 19 00:24:42 2002|291846|-|bakul|0|262301|1|May 19 
>00:24:42 2002|rwxr-xr-x|1095744|23996|-|bakul|stat
> > $ stat -a -n stat
> > 
>1021793082|48|1021793082|291846|0|1001|0|262301|1|1021793082|755|1095744|23996|100000|1001|stat
>
> Bow to me.
>
> echo 'ibase=2\nobase=8\n' \
>     `ls -ld ${FILE} | cut -f 1 -d " " | \
>      sed -e 's/[rwx]/1/g' -e 's/[^rwx1]/0/g'` | \
>      bc

Great idea to use bc(1) ;-) It doesn't really parse sticky, suid or
sgid bits, but it's smaller than the awk version.  The following did
the trick nicely (but is too ``complicated'', and I'd still like
having a tool that allows userland to call stat/fstat(2):

        hades+charon:/tmp$ cat foo.sh
        #!/bin/sh

        echo 'ibase=2;obase=8;' \
        ` ls -ld "$1" | \
        cut -c2-10 | \
        sed -e '/^..[sS]/ s/^.*$/&+100000000000/' \
            -e '/^.....[sS]/ s/^.*$/&+10000000000/' \
            -e '/^........[tT]/ s/^.*$/&+1000000000/' | \
        sed -e 's/[st]/x/g' -e 's/ST/-/g' | \
        sed -e 's/[rwx]/1/g' | \
        sed -e 's/[^1+]/0/g' ` | bc

        % sh foo.sh /tmp
        hades+charon:/tmp$ sh foo.sh /tmp
        1777

-- 
Giorgos Keramidas    - http://www.FreeBSD.org
[EMAIL PROTECTED] - The Power to Serve

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to