Previous Table of Contents Next


Special Modes

The set-user-ID, set-group-ID, sticky bit, and file locking modes are special modes providing more flexibility in how UNIX handles the execution of a file.

The set-user-ID is reflected in the user execute position. It allows a different user to assume the user-ID of the file. Thus you execute the file (program) as if logged in as the owner of the file. For example, the following file belongs to the user "luwis:"

       -rwsr-xr-x    1  luwis       ts         1 Jan 20 17:11 testprog

If you execute the testprog file, you will execute it as though the user luwis was executing it. This is useful to provide access to secure data via controlled program environments.

The set-group-ID works on the same principal except when you execute it, the group-ID of the file is assumed, not the user-ID. The set-group-ID is displayed as the group execute position as shown in the following example:

       -rwxr-sr-x    1  luwis       ts         1 Jan 20 17:11 testprog

If either position is occupied by a capital S instead of a lowercase s, you can access the file as though you are the owner but you cannot execute the file.

If the sticky bit is enabled, a lowercase t is placed in the others execute position. The sticky bit informs the system to keep the program text of the file loaded in memory. For example, the following file will be executed. When you exit from it the system will not unload it from memory.

       -rwxr-xr-t    1  luwis       ts        1 Jan 20 17:11 testprog

If a capital T is present, then the file is not executable and can never be loaded into memory. Therefore, it is an undefined permission or state of the file. Only the super-user can set the sticky bit.

File locking is enabled if the group execute position is set to lowercase l. The l represents mandatory file and record locking. If file locking is enabled, a file is temporarily unavailable to all other users while it is being accessed. The following example shows the position of the l in the modes:

       -rwxr-lr-x    1  luwis       ts        1 Jan 20 17:11 testprog

RELATED COMMANDS

Refer to the chgrp, chmod, chown, ln, mv, rm, and find commands described in modules 16, 17, 18, 76, 91, 114, and 55, respectively.

RELATED FILES

The following list of files are used by the ls command.

/etc/passwd The user IDs are matched for the ls -l and ls -o options.
/etc/group The group IDs are matched for the ls -l and ls -g options.
/usr/share/lib/terminfo/?/* The terminal definition database for screen control (SV)
/etc/termcap The terminal definition database for screen control (BSD)

APPLICATIONS

The ls command is an essential utility. You use it to know what files exist in your directories. Using options, you can list hidden files (files beginning with a period). Certain options display who owns the file and to which group it belongs. All information about a file can be displayed using the ls command.

ls is often used in shell scripts to display the directory for selecting a filename. You may wish to process each file in a loop by using ls to perform the list part of a for loop.

TYPICAL OPERATION

In this activity you use the ls command to list the files in your HOME directory and other directories using different options. Begin at the shell prompt.

1.  Type ls and press Return. Notice that a one-column list of files is returned. If you are on BSD the output will be multicolumn.
2.  Now type ls -CF and press Return. Your screen looks like the following display:
       cj> ls -CF
       /bin    calendar  db/       file1     file2     letters/
3.  Type ls -l and press Return. A complete listing is displayed.
       cj> ls -l
       total 1
       drwsr-xr-- 2 rjf  ts     24 Jan 24 07:12 bin
       -rw-r--r-- 1 rjf  ts    107 Jan 24 08:45 calendar
       drwxr-xr-- 1 rjf  ts    512 Jan 24 07:17 db
       -rw-r--r-- 1 rjf  ts     70 Jan 24 07:25 file1
       -rw-r--r-- 1 rjf  ts    161 Jan 24 07:01 file2
       drwxr-xr-- 1 rjf  ts     24 Jan 24 07:12 letters
4.  Turn to Module 14 to continue the learning sequence.


Previous Table of Contents Next