File Protection
Unix provides a mechanism for permitting access to files and
directories by other users. For every file and directory in the file
system, there are three classes of users who may have access:
- User (u)
- The user is the owner of the file, usually the person who created it initially.
- Group (g)
- All users are assigned one or more user groups. Therefore, there is also a group ownership associated with each file.
- Other (o)
- All users other than the owner of the file or a member of the file's group.
- All (a)
- All users (User, Group, and Other).
Each of these options is abbreviated to its first letter.
Let's examine the output from "ls -alg". The "-g" option causes "ls" to
display the group ownership of a file. The "-a" and "-l" options cause all
files to be displayed in long format.
total 10
drwxr-xr-x 3 jsmith admin 512 Apr 5 16:29 .
drwxr-xr-x 4 jsmith admin 512 Apr 5 08:48 ..
-rw-r--r-- 1 jsmith admin 2315 Apr 5 16:29 mklogin.c
-rw-r--r-- 1 jsmith admin 0 Apr 5 16:29 mt
-rw-r--r-- 1 jsmith admin 2053 Apr 5 16:14 test.c
The information in the left-most column (in this example, d or -) tells
whether the entry is a directory or a normal file. The next nine
columns are divided into three groups of three characters, giving the
permissions for the User, Group, and Others, respectively. The three
permissions are:
- Read (r)
- A user with read permission for a file can look at the contents of the file. If the file is a directory, then the user can find out what files are contained in that directory using the "ls" command.
- Write (w)
- A user with write permission for a file can change its contents. Having write permission for a directory allows a user to create or delete files contained in that directory.
- Execute (x)
- A user who has execute permission for a file can use that file as a Unix system command. Execute permission for a directory allows access to the files contained within the directory, and it allows one to move to that directory.
The next number in the output from "ls" is the link count for the file,
with which you need not concern yourself. The user and group ownership
of the file are given next, followed by the size of the file in
characters. The last information given before the name of the file is
the date and time at which the file was last modified.
Click here to go to the next
section.
Or click here to go to the top of the
chapter.