Display permissions in octal format

Hi,

Is there any way to display the permissions in octal format rather than "rwxrwxrwx" format.

I have a file and i want to see the permissions in octal format. Please help.

perl -e'printf "%o\n",(stat shift)[2]' filename

Okay this is working .

i checked one file with permissions -rw-r--r-- and this code is showing it as 100644.

Can any one explain what 100 means here ??

you need to add the bitwise AND

perl -e'printf "%o\n",(stat shift)[2] & 07777'

from the perldoc

Right,
thanks for the correction!

Thanks a lot...

perl -e'printf "%o\n",(stat shift)[2] & 07777' ---- This is working.

But i donno perl. Is there anyway to achieve the same in unix.

On many Unix/Linuxes there is perl basically installed. Did you try it?

I tried it and it is working fine. No issues. However i just want to know anyother command in unix with which we can achieve the same. Because i am new to Perl.

Without perl it's a lot of work. Try this:

#!/bin/ksh
ls -ld $* | awk 'BEGIN {
v["r1"]=400; v["w2"]=200; v["x3"]=100; v["s3"]=4100; v["S3"]=4000
v["r4"]=40 ; v["w5"]=20 ; v["x6"]=10 ; v["s6"]=2010; v["S6"]=2000
v["r7"]=4  ; v["w8"]=2  ; v["x9"]=1  ; v["t9"]=1001; v["T9"]=1000}
{val=0
 for (i=1;i<=9;i++) val=val+v[substr($0,i+1,1)i]
 printf "%4d %s\n",val,$NF}'

From: this old thread

What is the platform?

Sun solaris

You may try to parse the output of pkgproto, something like this (recursive):

find .  -exec pkgproto {} + | cut -d\  -f3,4

Or just:

pkgproto * | cut -d\  -f3,4
pkgproto filename | cut -d\  -f3,4

Use -f4 if you wnat to display only the permissions.