1

I am studying for a public exam and see this question (pt-BR) Before answer, I read about chmod and understood that the permission are split in 3 groups (user, group, other), like this:

    Nível  u   g   o
Permissão rwx r-x ---
  Binário 111 101 000
    Octal  7   5   0

So, why are there more than 9 (3x3) char in the permission string (-r--rwx-rw-)

dervishe
  • 465
  • You've a typo in your example. You have 11 possible positions, whereas in reality there should be 10 possible positions. That's still one more than the 9 you suggested. The additional left had position can be a d to signify a directory. Therefore you have drwxrwxrwx. man chmod explains the codes. info ls has even more information. – garethTheRed Feb 01 '16 at 15:26
  • Why wouldn't there be more than 9 positions? You already have read,write and execute for user, group and other, giving nine bits, and then there are things like the SUID, GUID and sticky bits – Anthon Feb 01 '16 at 15:29
  • chmod u=,g=rwx,o= – vonbrand Feb 01 '16 at 16:53

2 Answers2

4

Either read in the "Explanation" field in the table below what you want to do, or do ls -l and see what it means. Each object (file, directory, sockets, device, etc) has 10 positions to indicate what's possible with the object. For example you could see -rwxr-x---. You can split the 10 positions up into these parts:

The 1st character: what kind of object is it; - for file, d for directory, s for socket.
The 2nd until and including the 4th character: the permissions for the owner of the object.
The 5th until and including the 7th character: the permissions for the group that owns the object.
The 8th until and including the 10th character: the permissions for others.

Numeric  Readable    Explanation
0        ---         No access.
1        --x         Execute access.*
2        -w-         Write access.**
3        -wx         Write and execute access.***
4        r--         Read access.
5        r-x         Read and execute access.
6        rw-         Read and write access.
7        rwx         Read, write and execute access.

sources : http://meinit.nl/linux-permission-numberic-table

Yunus
  • 1,684
4

That would be 476. A good way to remember is that read has the value of 4, write has the value of 2, and execute has the value of 1.

Also, the first number is dedicated to owner, the second number to group, and the third one to other.

       owner group other
Read     4    4    4
Write    2    2    2
Execute  1    1    1

You add the numbers together, when there are more privileges. So r-x would be 5, because 4+1 is logically 5


Also, the letter before the rwxrwxrwx, sometimes displayed as -, is the file type. When you see something like drwxrw-r--; the D means directory. Notice that when listing with ls -l, all the directories have the d on start of their permission string, and all files have a -.

Apart from d, and dash (-), there is also s for sockets, l for symlinks, c and b for device files, D (capital) for doors, p for named pipe.

Don't worry much about Doors, as they are currently only implemented in the Solaris OS.

John K
  • 534