Can this be tweaked for directories also? You lost me after tr.
Check it out: tr -- '-drlwcxb' '0 1 1 1 ' Says (somewhat obfuscatedly): --: ignore the - in the next string '-drlwcxb': characters to match on input '0 1 1 1 ': characters to replace with The mapping is positional: - becomes 0 d becomes space r becomes 1 l becomes space w becomes 1 c becomes space x becomes 1 b becomes space "season to taste" implies that you'd hack in cases for 'p' '=' and the few remaining other cases. You'll also need to map 's' and 't' to 1 to cover setuid/setgid and sticky. If you need to know about the setuid/setgid and sticky bits and the file type stuff you can let tr pass them and them scan: FMODE=$(echo $STR|tr 'rwx' '111') # check file types case "$FMODE" in b*) # block file stuff FT=0110 ;; c*) # char file stuff FT=0010 ;; d*) # directory stuff FT=0100 ;; l*) # symlink stuff FT=1010 ;; p*) # named pipe (fifo) stuff FT=0001 ;; =*) # socket file stuff FT=1010 ;; -*) # regular file stuff FT=1000 ;; esac # check higher bits case "$FMODE" in ???s??????) # setuid stuff XM=100 ;; ??????s???) # setgid stuff XM=010 ;; ?????????t) # sticky stuff XM=001 ;; esac # normalize file types to ' ' and s, t bits to 1 BINMODE=$(echo $FMODE | tr -- '-bcdlp=st' ' 11') # translate full mode to octal OCTMODE=$(echo "ibase=2; obase=8; $FT$XM$FMODE" | bc) At some point you wake up to stuff like: perl -e '@x = stat("foo"); printf "%o\n", $x[2]' ccb -- Charles C. Bennett, Jr. VA LiNUX Systems Systems Engineer, Northeast US 25 Burlington Mall Rd., Suite 300 +1 617 543-6513 Burlington, MA 01803-4145 ccb@valinux.com www.valinux.com