InterviewSolution
| 1. |
File Permission Commands |
|||||||||||||||
|
Answer» There are 3 types of people who can use a file and each type has 3 types of access to the file. This is shown in the diagram given below: The diagram shows that there are 3 types of people accessing a file and they are:
Also, the access that we want to give to each of them is of three types:
So, each of them can have 0 or more out of these 3 permissions. Now let us understand the Linux commands that help us give these permissions to the files.
Before we jump into the Linux file permission commands and see some examples, it is very important to understand this chmod command in detail first as understanding this command completely will clear the entire concept of file permission commands. The chmod command stands for “change-mode” which means that using this command, we can change the mode in which some user is able to access the file. This command is used to change the file permissions. The syntax can be either using symbols (characters) or numbers. We will see that in detail.
This is the first method of chmod command using which we can give permissions. The basic syntax is as follows: chmod [ugoa…][-+=]perms…[,....] FILE…. Let us understand this syntax in detail. The first set means the type of person to give access to. Here:
If the user's flag is not included in the command i.e. we do not mention for which kind of people out of u, g and o, are we changing the permissions for, by default, it takes a i.e. all the users. The second set is the set of operators. Let us see what they mean.
The perms stand for permission and ‘,’ is used to separate different permissions. Let us now see the Linux commands using the symbolic notation of chmod.
There are numeric codes for each permission. They are as follows:
The permissions number of a specific user class is represented by the sum of the values of all the permissions. For instance, if the user has read and executed permissions, but not the write permission, then the permissions number for the user will be read (4) + execute(1) = 5. For instance, if we have to write a command to provide read and write permissions to the user, group and others, there can be many ways of doing so. Let us see one symbolic way:
$ chmod ugo+rw file1.txt We can write this in a numeric way as shown below:
$ chmod 666 file1.txt Explanation: We have already studied that if we do not mention u/g/o then by default the permissions are applied to all. Also, read + write = 4 + 2 = 6. We have written 6 thrice because of applying the permissions to user, group and others. So, read and write permissions are applied to the user, group and others (666) for the file file1.txt. |
||||||||||||||||