Previous Table of Contents Next


FURTHER DISCUSSION

The default listing produced by ls is a single-column list of the current directory. Hidden files (files starting with a period) are not listed. By specifying an option you can change the output format, sorting order, or the files that are listed. If you provide specific filenames and directories as arguments, ls will list the filenames first. Each directory and its contents are listed. The options you use are applied throughout the listing.

There are three basic types of output formats:

1.  One entry per line (short or long information).
2.  Multicolumn formats (sorted down or across).
3.  Stream format (all entries on the same output line).

Environment Variables for Multicolumn Format

The multicolumn options require knowledge about your terminal screen width. To decide how many columns your terminal screen has, ls uses the value of the COLUMNS variable. If COLUMN is not set, ls uses the termcap or terminfo database to retrieve your terminal's screen width. The terminal type defined in the TERM variable is used for the database reference. If the necessary information is not retrieved, then 80 columns are assumed.

Aliases

The ls command with certain options is often aliased to shorthand names. Some systems are shipped with these commands already available. If you have the Korn or C shells, you can create aliases. If you only have the Bourne shell, you can create shell scripts.

The aliases are:


Korn shell C shell

alias    l="ls -m" alias l   ls -m
alias   ll="ls -l" alias ll   ls -l
alias lsf="ls -F" alias lsf ls -F
alias lsr="ls -R" alias lsr ls -R
alias lsx="ls -x" alias lsx ls -x

The shell scripts are:

      cj> cat l
      exec ls -m $*

      cj> cat ll
      exec ls -l $*

      cj> cat lsf
      exec ls -F $*

      cj> cat lsr
      exec ls -R $*

      cj> cat lsx
      exec ls -x $*

Modes

The -l option returns the most information by itself about each file. The first ten characters of the listing produced by the -l option are referred to as the file mode. The following is an example of the -l output for one file:

The mode consists of the file type and the file permissions.

File type

The first character of the mode indicates the type of file. The following table defines each possible file mode character:


Character File Type

b The file is a block special file. A block special file describes a device driver that performs I/O in blocks of data.
c The file is a character special file. A character special file describes a device driver that performs I/O character by character.
d The file is a directory. The structure of the file is that of a directory.
p The file is a FIFO (named piped). A named pipe is used for inter process communications, where two or more processes communicate with one another. (FIFO is an abbreviation for First In/First Out an I/O concept, sometimes referred to as a queue)
- The file is an ordinary file. You may store whatever type of data you desire in this type of file.

File Permissions

The next nine characters of the mode describe the permissions that allow or restrict users from accessing the file. The nine characters can be separated into three fields of three. The following examples show each field's use:

--rwx------ The read, write, and execute permissions for the owner.
-----rwx-- The read, write, and execute permissions for group members.
--------rwx The read, write, and execute permissions for other users.

The first line shows the user read, write, and execute positions as being set. The second line shows the groups read, write, and execute positions as being set. And the third shows the others read, write, and execute positions as being set. The following table defines the possible characters found in the permissions field:


Character Definition

r Allowed to read the file
w Allowed to write to the file
x Allowed to execute the file (program)
l Mandatory file locking will occur when the file is accessed. The set-group-ID must be enabled and group execution must be disabled.
s Set-user-ID or set-group-ID execution is enabled (see following description of s and S).
S Set-user-ID or set-group-ID is enabled but the file is not executable (not a defined mode).
t Sticky bit and execution are enabled.
T Sticky bit is enabled but the file is not executable (not a defined mode).

Directory Permissions

The permissions on a directory are restricted to the read, write, and execute permissions. The execute permission is interpreted as the search permission. That is, users in the group with the execute permission enabled are allowed to search the directory for files.


Previous Table of Contents Next