Computer Science, asked by saiananth1998, 11 months ago

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

Answered by QGP
54

File Permissions in Unix

We are given the file \texttt{dept.txt}

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 \texttt{rwx rw- r--} 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 \texttt{dept.txt} file has the permissions \texttt{rw- --- ---}

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:

\texttt{chmod permissions filenam}\texttt{e}

\rule{300}{1}

Symbolic Notation

In Symbolic Notation, we can change permissions using three characters:

\begin{tabular}{c|l}\textbf{\textsf{Symbol}} & \textbf{\textsf{Description}}\\\cline{1-2}\sf + &\sf Add permission \\\sf - & \sf Remove permission \\\sf = &\sf Assign permission and override previous permissions \end{tabular}

The symbols for the different user types are as follows:

\begin{tabular}{c|l} \textbf{\textsf{Symbol}} & \textbf{\textsf{User Type}} \\ \cline{1-2} \sf u & \sf Owner/User \\ \sf g & \sf Group \\ \sf o & \sf Other \\ \sf a & \sf All user types \end{tabular}

So, for example, \texttt{dept.txt} currently has permissions of \texttt{rw- --- ---}

Then, doing \texttt{chmod o=r-- dept.txt} will assign the permission of \texttt{r--} to the Other user type for the file. The new permissions will be \texttt{rw- --- r--}

Now, if we do \texttt{chmod a+x dept.txt} we are adding the execute permission to all the user types. The new permissions will look like  \texttt{rwx --x r-x}

Answer:

We just want to add the Write permission to Group and retain everything else. So, the command using symbolic notation is

\boxed{\texttt{chmod g+w dept.txt}}

 \rule{300}{1}

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:

\begin{tabular}{c|l|c} \textbf{\textsf{Digit}} & \textbf{\textsf{Permission}} & \textbf{\textsf{Symbol}} \\ \cline{1-3}\tt 0 &\sf No Permission &\tt --- \\ \tt 1 &\sf Execute &\tt --x \\ \tt 2 &\sf Write &\tt -w- \\ \tt 3 &\sf Write + Execute &\tt -wx \\ \tt 4 &\sf Read &\tt r-- \\\tt 5 &\sf Read + Execute &\tt r-x \\\tt 6 &\sf Read + Write &\tt rw- \\\tt 7 &\sf Read + Write + Execute &\tt rwx \\\end{tabular}

This assigns absolute permissions and overrides previous permissions.

For example, doing \texttt{chmod 754 dept.txt} will assign the following permissions:

  • 7: \texttt{rwx} permissions to user/owner
  • 5: \texttt{r-x} permissions to group
  • 4: \texttt{r--} permissions to other  

All previous permissions are overridden.

Answer:

The \texttt{dept.txt} file has permissions \texttt{rw- --- ---}. 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 \texttt{-w-} permissions, which corresponds to the digit 2.

So, our final digits are 620.

Hence, we use the command:

\boxed{\texttt{chmod 620 dept.txt}}

\rule{300}{1}

Summary

\texttt{dept.txt} has the permissions \texttt{rw- --- ---}

We want the new permissions to be  \texttt{rw- -w- ---} .

We can use either of the two commands:

Symbolic Notation: \texttt{chmod g+w dept.txt}

Octal Notation: \texttt{chmod 620 g+w dept.txt}

I have attached two screenshots showing these commands.

Attachments:
Answered by thapaavinitika6765
2

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

Similar questions