8

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
chaos
  • 48,171

2 Answers2

12

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
chaos
  • 48,171
  • 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).

Coder-guy
  • 111
  • 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 09 '15 at 12:35