-->
Previous | Table of Contents | Next |
These permission subfields can show more information; in fact, several attributes are packed into these three fields. Unfortunately, what these attributes mean is determined by the version of Linux you use and whether the file is executable.
NOTE: Normally, a running program is owned by whoever ran it. If the user ID bit is on, the running program is owned by the owner of the file. This means that the running program has all the permissions of the owner of the file. If youre an ordinary user and the running program is owned by the root user, that running program has automatic permission to read and write any file in the system regardless of your permissions. The same is true of the set group ID bit.
The sticky bit can also be set in these subfields. The sticky bit tells the system to save a copy of a running program in memory after the program completes. If the program is used often, the sticky bit can save the system a little time the next time it runs the program because the program doesnt have to be reloaded into memory from disk each time someone runs it.
You can change permissions on any file you have write permission for by using the chmod command. This command has two different syntaxes: absolute and relative. With absolute permissions, you define exactly what the permissions on a file will be in octal, or base 8. An octal number can have a value from 0 to 7. UNIX was originally created on a series of DEC minicomputers that used the octal numbering system, hence the current use of octal numbers. The octal numbers are added together to arrive at a number that defines the permissions. Table 16.3 lists the valid octal permissions.
Octal Value | Permissions Granted |
---|---|
0001 | Execute permission for the owner |
0002 | Write permission for the owner |
0004 | Read permission for the owner |
0010 | Execute permission for the group |
0020 | Write permission for the group |
0040 | Read permission for the group |
0100 | Execute permission for all others |
0200 | Write permission for all others |
0400 | Read permission for all others |
1000 | Sticky bit on |
2000 | Group ID bit on if the file is executable; otherwise, mandatory file locking is on |
4000 | User ID bit on if the file is executable |
Group and user IDs refer to who has permission to use, read, or execute a file. These initial file permissions are granted by the systems administrator when the users account is first created. Only users of an indicated group can access files in a group, and only if the user has given group members permission to those files.
To give a file read and write permissions for everyone, you must add the required permissions together, as in the following example:
0002 | Write permission for the owner |
0004 | Read permission for the owner |
0020 | Write permission for the group |
0040 | Read permission for the group |
0200 | Write permission for all others |
0400 | Read permission for all others |
0666 | Read and write permission for everyone |
To give a file these permissions, you would use the following command:
chmod 666 file
Relative permissions use a slightly different format. With relative permissions, you must state the following:
For example, if you type chmod a=rwx file, you give read, write, and execute permission to all users. Table 16.4 summarizes the commands for relative permissions.
Value | Description |
---|---|
Whom | |
a | All users (the user, their group, and all others) |
g | Owners group |
o | All others not in the files group |
u | Just the user |
Operator | |
+ | Adds the mode |
- | Removes the mode |
= | Sets the mode absolutely |
Permission | |
x | Sets execute |
r | Sets read |
w | Sets write |
s | Sets user ID bit |
t | Sets sticky bit |
If a file has been marked as having the user ID bit on, the permissions displayed by the ls -l command look like this:
-rws------ 1 sglines 3136 Jan 17 15:42 x
If the group ID bit is added, the permissions look like this:
-rws--S--- 1 sglines 3136 Jan 17 15:42 x
If you then turn on the sticky bit for the file, the permissions look like this:
-rws--S--rws--S--T 1 sglines 3136 Jan 17 15:42 x
Note the use of uppercase S and T to indicate the status of the user ID bit and the sticky bit, respectively.
Youre already familiar with the concept of directories. When you log in, the system places you in your home directory. The PATH environment variable is set to point to other directories that contain executable programs. These other directories are part of the standard Linux directory structure.
There is the classic set of directories for UNIX and what can be called the emerging standard set of directories, which Linux basically follows. These are described in the following sections.
Before UNIX System V Release 4 (for example, UNIX System V Release 3.2 and earlier), most versions of UNIX settled on a regular system of organizing the UNIX directories that looked like this:
/ /etc /lib /tmp /bin /usr /spool /bin /include /tmp /adm /lib
The /etc directory contains most of the system-specific data required to boot, or bring the system to life. It contains such files as passwd and inittab, which are necessary for the proper operation of the system.
Previous | Table of Contents | Next |