Existing permission for file dept.txt is rw- --- --- . Retain the same permissions for user and other category. Add write permission to group using octal notation or symbolic notation in unix.
Answers
File Permissions in Unix
We are given the file
Unix systems divide users into three categories:
- Owner/User - This is the owner of the file
- Group - Users belonging to predefined user group
- Other - All other users
These three are denoted by the letters u (user/owner), g (group) and o (other) respectively.
For each user type, there can be three types of permissions for any file:
- Read - r - User can read the file
- Write - w - User can edit the file
- Execute - x - User can execute the file (if it is an executable file like a program code or application)
The absence of a permission is denoted by a hyphen ( - ).
File permissions are mentioned in 3 letter codes. For example, a file permission of means that:
- Owner can read, write and execute the file.
- Group can read and write the file, but not execute it
- Other can only read the file
The file has the permissions
This means that:
- Owner can read and write the file, but not execute it
- Anyone else cannot do anything to the file, not even read it
File permissions can be edited using the chmod command.
Syntax:
Symbolic Notation
In Symbolic Notation, we can change permissions using three characters:
The symbols for the different user types are as follows:
So, for example, currently has permissions of
Then, doing will assign the permission of to the Other user type for the file. The new permissions will be
Now, if we do we are adding the execute permission to all the user types. The new permissions will look like
Answer:
We just want to add the Write permission to Group and retain everything else. So, the command using symbolic notation is
Octal Notation
In octal notation, we assign permissions using the digits 0-7 for each user type. So, we use a three digit code to assign permission for u, g and o. The three digits are in octal.
The reference table:
This assigns absolute permissions and overrides previous permissions.
For example, doing will assign the following permissions:
- 7: permissions to user/owner
- 5: permissions to group
- 4: permissions to other
All previous permissions are overridden.
Answer:
The file has permissions . These correspond to the digits 600.
We are retaining the permissions for user and other. So, 6 and third digit 0 will remain same. We want to add write permission to group. So, for group, we want the permissions, which corresponds to the digit 2.
So, our final digits are 620.
Hence, we use the command:
Summary
has the permissions
We want the new permissions to be .
We can use either of the two commands:
Symbolic Notation:
Octal Notation:
I have attached two screenshots showing these commands.
Read - r - User can read the file
Write - w - User can edit the file
Execute - x - User can execute the file (if it is an executable file like a program code or application