This question already has an answer here:

I know that with "ls -l" I can see the permissions of a file or directory but it shows them with letters, so how to show the permissions in numeric way

for example:

755 /var/www/mywebpage

marked as duplicate by Jeff Schaller, Stephen Rauch, Anthon, Rui F Ribeiro, Gilles 'SO- stop being evil' files Aug 12 '17 at 22:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You could use find :

find . -maxdepth 1 -printf "%m %f\n"

or stat:

stat -c "%a %n" -- *

Like stated in this answer on stackoverflow,

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

is doing exactly what you want.

  • It doesn't handle setuid and setgid files correctly. – sebasth Aug 12 '17 at 20:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.