Can the Unix list command 'ls' output numerical chmod permissions? Can the Unix list command 'ls' output numerical chmod permissions? unix unix

Can the Unix list command 'ls' output numerical chmod permissions?


it almost can ..

 ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \             *2^(8-i));if(k)printf("%0o ",k);print}'


Closest I can think of (keeping it simple enough) is stat, assuming you know which files you're looking for. If you don't, * can find most of them:

/usr/bin$ stat -c '%a %n' *755 [755 a2p755 a2ps755 aclocal...

It handles sticky, suid and company out of the box:

$ stat -c '%a %n' /tmp /usr/bin/sudo1777 /tmp4755 /usr/bin/sudo


you can just use GNU find.

find . -printf "%m:%f\n"