Each file in Unix has an owner -
normally the user who creates the file. The file also belongs to a particular
group.
A group in Unix is a set of users. For instance, all faculty in CSE belong
to the group cisfact. Similarly, all CSE graduate students belong
to the group cisgrad.
|
|
For controlling access to a file, Unix divides all users into three classes :
Read permission allows users to view the contents of a file and to copy it. Write permission allows users to modify the file. Execute permission allows users to run the file, if it is executable.
The permissions for a file can be listed using the ls -l command. Here's a sample output of such a command:
-rwxr-x--x 1 smith cisgrad 243 Jun 30 1996 chessThe first character of the output can be either a "-" or a "d". A "d" means that the item is a directory. A "-" means the item is a regular file.
The next nine characters indicate the permissions for the file. Of these, the first 3 denote the permissions for the owner of the file. The next 3 denote the permissions for the group members. The last 3 denote the permissions for everyone else.
In this case, the owner of the file has "r", "w" and "x" permissions, group members have "r" and "x" permissions but no "w" permission and others have only "x" permission. Lookup the ls command for details on the other fields of the output.
In the case of directories, permissions are interpreted in a slightly different way. Read permission allows users to list the contents of the directory. Write permission allows users to create files and sub-directories within the directory and execute permission allows users to search the directory. A file or directory can be accessed using a pathname ONLY if the user has execute (search) permission on all intermediate directories in the path.
File permissions can be manipulated using the chmod command. The chmod command allows you to set, add or remove "r", "w" and "x" permissions. For example, to set the group permission for the file lab1.cpp to "r" and "w", you would use the command:
chmod g=rw lab1.cpp
To allow execute permission for the group, in addition to existing permissions, use the command:
chmod g+x lab1.cpp
To deny write permission to the group, use the command:
chmod g-w lab1.cpp
Changing the permissions for the owner and others is similar. For the
owner, use "u" (for user) instead of "g", and for others use "o".
|
Note that the command fails because you are not the owner of the directory. Let us copy all the files in the directory /class/sce/reference/unix/samples to the directory Testdir1. Can you guess the command to do this?
|
| Previous | Table of Contents | Continue |