Can the Unix list command 'ls' output numerical chmod permissions?
Is it possible when listing a directory to view numerical unix permissions such as 644 rather than the symbolic output -rw-rw-r--
Thanks.
Solution 1:
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}'
Solution 2:
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 a2p
755 a2ps
755 aclocal
...
It handles sticky, suid and company out of the box:
$ stat -c '%a %n' /tmp /usr/bin/sudo
1777 /tmp
4755 /usr/bin/sudo