6

I have set of linux folders and I need to get the permissions of the folders numerically.

For example in the below directory, I need to what is the permission value of the folder... Whether 755, 644 or 622 etc...

drwxrwsr-x 2 dev    puser 4096 Jul  7  2014 fonts
  • 1
    stat -c "%a %n" ? Without %n only permissions. – taliezin Mar 6 '15 at 21:56
9

To get the octal permission notation.

stat -c "%a" file
644

See the manpage of stat, -c specifies the format and %a prints the permissions in octal.

Or for multiple files and folders:

stat -c "%a %n" *
755 dir
644 file1
600 file2
| improve this answer | |
  • Nice, also you could create a function; it might work: lso() { ls -alG "$@" | 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}'; } and then just type lso – Junior Mayhé Jun 27 '15 at 18:45
1

Folder permissions are in the form rwx rwx rwx. They correspond to Owner Group Other respectively. The values are basically binary. x(execute) is the furthest right so the value is 1, next is w(write) and the value is 2. r(read) has the value of 4. If you add these up you can see that your folder, fonts, has a value of 775 (Owner(rwx)Group(rwx)Other(rx).

| improve this answer | |
  • You also need to know that the "S" bits come before the regular permissions, so the drwxrwsr-x from the question has xsx, which boils down to binary 010, with is 2. So the full octal interpretation of rwxrwsr-x is 2775. – wurtel Mar 9 '15 at 12:35

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