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

Jon Winstanley picture Jon Winstanley · Nov 25, 2009 · Viewed 112.4k times · Source

Is it possible when listing a directory to view numerical unix permissions such as 644 rather than the symbolic output -rw-rw-r--

Thanks.

Answer

miku picture miku · Nov 25, 2009

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}'