Introductiontolinux




Download 4,86 Mb.
Pdf ko'rish
bet15/18
Sana23.12.2023
Hajmi4,86 Mb.
#127288
1   ...   10   11   12   13   14   15   16   17   18
Bog'liq
introductiontolinux

Using the Binary Method
Through the binary method, each permission is assigned a binary value and added together to give 
a three digit number, one digit for each party (user, group, other). The end result will be something 
along the lines of ‘chmod 755 test.sh’, which assigns the permissions of User=Read, Write Execute; 
Group=Read, Execute; Other=Read, Execute. The binary values for each permission are Execute=1, 
Write=2, Read=4. If you wanted to assign a party read and write only permissions, then it would be 
a total of 6, while a party with permissions of read only would be 4. E.g: 
To change a file called ‘phonebook’ (located 
in the same folder you are currently inside) to 
User=RWX, Group=RX, Other=R (as above), 
you would therefore run the command ‘chmod 
754 phonebook’ . Lets try this now:
cd ~/unixintro
pwd
ls -la
cat phonebook
chmod 044 phonebook
cat phonebook
Changes Directory to ‘unixintro’, 
located inside your home directory
Print the current working directory 
and check it’s correct.
List the contents of the working 
directory
Make a note of the original 
permissions for ‘phonebook’ - you 
will need to restore them!
Read the contents of the file 
‘phonebook’
Change permissions of ‘phonebook’
Now try to read the file ‘phonebook’. 
What happened?
Now restore the original permissions 
and try again


28
 |
Using the Symbolic Method
Using the Symbolic Method, you can set permissions exactly like you do using the Binary method. 
The only difference is you use a verbose way of setting the permissions instead of a mathematical 
way. To do set the same permissions as in the Binary Method example, we would use the commands: 
‘chmod u=rwx,g=rx,o=r test.sh’. You can work out how to build the command up each time using 
a very simple table. Note that in the example above we have used commas (,) to separate each 
permissions for each party.
Some other examples of chmod using the Symbolic method are as follows:
Lets try this using the same example as in the binary method.
cd ~/unixintro
pwd
ls -la
cat phonebook
chmod u=,g=r,o=r phonebook
cat phonebook
Changes Directory to ‘unixintro’, 
located inside your home directory
Print the current working directory 
and check it’s correct.
List the contents of the working 
directory
Make a note of the original 
permissions for ‘phonebook’ - you 
will need to restore them!
Read the contents of the file 
‘phonebook’
Change permissions of ‘phonebook’
Now try to read the file ‘phonebook’. 
What happened?
Now restore the original permissions 
and try again



Download 4,86 Mb.
1   ...   10   11   12   13   14   15   16   17   18




Download 4,86 Mb.
Pdf ko'rish