6

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

0

2 Answers 2

15

You could use find :

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

or stat:

stat -c "%a %n" -- *
1
  • actually just stat works perfect.
    – 8ctopus
    Jul 27, 2023 at 5:15
1

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.

2
  • It doesn't handle setuid and setgid files correctly.
    – sebasth
    Aug 12, 2017 at 20:14
  • 1
    Love this one-line solution answer. Exactly what I needed! Apr 30, 2022 at 23:42

Not the answer you're looking for? Browse other questions tagged .