ls(1) ls(1)
ls - list contents of directory
ls [-RadLCxmlnogrtucpFbqisf1AMSDP] [names<b>]
For each directory argument, ls lists the contents of the directory; for
each file argument, ls repeats its name and any other information
requested. The output is sorted alphabetically by default. When
arguments are not given, the current directory is listed. When several
arguments are given, the arguments are first sorted appropriately, but
file arguments appear before directories and their contents. ls
processes supplementary code set characters according to the locale
specified in the LC_CTYPE and LC_COLLATE environment variables [see LANG
on environ(5)], except as noted under the -b and -q options below.
There are three major listing formats. The default format for output
directed to a terminal is multi-column with entries sorted down the
columns. The options -C and -x enable multi-column formats; and the -m
option enables stream output format, in which files are listed across the
page, separated by commas.
To determine output formats for the -C, -x, and -m options, ls uses an
environment variable, COLUMNS, to determine the number of positions
available on one output line. If this variable is not set, and the
output is directed to a terminal, the number of positions is obtained
from the terminal device. If this information cannot be obtained, 80
columns are assumed.
The ls command has the following options:
-R Recursively list subdirectories encountered.
-a List all entries, including those that begin with a period (.),
which are normally not listed.
-A Like -a except it does not list the . and .. directories.
-d If an argument is a directory, list only its name (not its
contents); often used with -l to get the status of a directory.
-L When listing status, if an argument is a symbolic link, list the
status of the file or directory referenced by the link rather than
that of the link itself. This option will have no effect if the
argument is a dangling link.
-H If the file is a symbolic link, list the file itself. This is the
default behavior, except for a symbolic link to a directory in the
absence of the -l option, in which case the -L behavior is used by
default. -H and -L cancel one another in command line order.
Page 1
ls(1) ls(1)
-C Multi-column output with entries sorted down the columns. This is
the default output format.
-x Multi-column output with entries sorted across rather than down the
page.
-m Stream output format; files are listed across the page, separated by
commas.
-l List in long format, giving mode, number of links, owner, group,
size in bytes, and time of last modification for each file (see
below). If the file has an Access Control List (ACL) the mode
specification will be followed by a ``+''. If the file is
a special file, the size field contains the major and minor device
numbers rather than a size. If the file is a symbolic link, the
filename is printed followed by ``->'' and the pathname of the
referenced file.
-n The same as -l, except that the owner's UID and group's GID numbers
are printed, rather than the associated character strings.
-o The same as -l, except that the group is not printed.
-g The same as -l, except that the owner is not printed.
-h When file sizes are printed, print them in a format that is easier
to read for large files. The size will consist of the number of
units followed by a unit specifier ('b' for bytes, 'K' for
kilobytes, 'M' for megabytes, 'G' for gigabytes, etc.)
-r Reverse the order of sort to get reverse alphabetic or oldest first
as appropriate.
-t Sort by time stamp (latest first) instead of by name. The default
is the last modification time. (See -u and -c.)
-u Use time of last access instead of last modification for sorting
(with the -t option) or printing (with the -l option).
-c Use time of last modification of the i-node (file created, mode
changed, and so on) for sorting (-t) or printing (-l).
-p Put a slash (/) after each filename if the file is a directory.
-F Put a slash (/) after each filename if the file is a directory, an
asterisk (*) if the file is executable, an equal sign (=) if the
file is an AF_UNIX address family socket, and an ampersand (@) if
the file is a symbolic link. Unless the -H option is also used,
symbolic links are followed to see if they might be a directory; see
above.
Page 2
ls(1) ls(1)
-b Force printing of non-printable characters to be in the octal \ddd
notation. All multibyte characters are considered printable.
-q Force printing of non-printable characters in file names as the
character question mark (?). All multibyte characters are
considered printable.
-i For each file, print the i-node number in the first column of the
report.
-s Give size in blocks, including indirect blocks, for each entry.
Holes in files are not included in the size. A ``block'' is 512
bytes.
-S Show the canonical device name associated with a special file, if it
can be determined.
-f Force each argument to be interpreted as a directory and list the
name found in each slot. This option turns off -l, -t, -s, and -r,
and turns on -a; the order is the order in which entries appear in
the directory.
-1 Print one entry per line of output.
-M Print the mandatory access control ( MAC ) label of each entry,
enclosed in square brackets. The -M option may be set automatically
by setting the environment variable LABELFLAG to the (case
insensitive) string "on", other values have no effect. If MAC is
not enabled, the square brackets will be empty.
-D Print the Access Control List ( ACL ) for the entry as an acl(4)
string enclosed in square brackets. If the ACL is empty or support
for ACLs is not installed, the square brackets will be empty.
-P Print the capabilities for the entry as a capabilities(4) string
enclosed in square brackets.
If MAC, ACL, and capabilities are all requested (-DMP in any order), the
entries are displayed in the order MAC, capabilities, ACL.
Specifying more than one of the options in the following mutually
exclusive pairs is not considered an error: -C and -l(ell), -m and
-l(ell), -x and -l(ell), -C and -1(one), -c and -u. The last option
specified in each pair determines the output format.
The mode printed under the -l option consists of eleven possible
characters. The first character may be one of the following:
d if the entry is a directory;
l if the entry is a symbolic link;
Page 3
ls(1) ls(1)
b if the entry is a block special file;
c if the entry is a character special file;
s if the entry is a XENIX semaphore;
m if the entry is a XENIX shared data (memory);
p if the entry is a fifo (named pipe) special file;
S if the entry is an AF_UNIX address family socket;
- if the entry is a regular file.
The next 9 characters are interpreted as three sets of three bits each.
The first set refers to the owner's permissions; the next to permissions
of others in the user-group of the file; and the last to all others.
Within each set, the three characters indicate permission to read, write,
and execute the file as a program, respectively. For a directory,
``execute'' permission is interpreted to mean permission to search the
directory for a specified file.
ls -l (the long list) prints its output as follows:
-rwxrwxrwx 1 smith dev 10876 May 16 9:42 part2
Reading from right to left, you see that the current directory holds one
file, named part2. Next, the last time that file's contents were
modified was 9:42 A.M. on May 16. The file contains 10,876 bytes. The
owner of the file, or the user, belongs to the group dev (perhaps
indicating ``development''), and their login name is smith. The number,
in this case 1, indicates the number of links to file part2 [see cp(1)].
Finally, the dash and letters tell you that user, group, and others have
permissions to read, write, and execute part2.
The execute (x) symbol here occupies the third position of the threecharacter
sequence. A - in the third position would have indicated a
denial of execution permissions.
The permissions are indicated as follows:
r the file is readable
w the file is writable
x the file is executable
- the indicated permission is not granted
L mandatory locking occurs during access (the set-group-ID bit is
on and the group execution bit is off)
s the set-user-ID or set-group-ID bit is on, and the corresponding
user or group execution bit is also on
S undefined bit-state (the set-user-ID bit is on and the user
execution bit is off)
t the 1000 (octal) bit, or sticky bit, is on [see chmod(1)], and
execution is on
T the 1000 bit is turned on, and execution is off (undefined bitstate)
Page 4
ls(1) ls(1)
For user and group permissions, the third position is sometimes occupied
by a character other than x or -. s also may occupy this position,
referring to the state of the set-ID bit, whether it be the user's or the
group's. The ability to assume the same ID as the user during execution
is, for example, used during login when you begin as root but need to
assume the identity of the user you login as.
In the case of the sequence of group permissions, L may occupy the third
position. L refers to mandatory file and record locking. This
permission describes a file's ability to allow other files to lock its
reading or writing permissions during access.
For other permissions, the third position may be occupied by t or T.
These refer to the state of the sticky bit and execution permissions.
An example of a file's permissions is:
-rwxr--r--
This describes a file that is readable, writable, and executable by the
user and readable by the group and others.
Another example of a file's permissions is:
-rwsr-xr-x
This describes a file that is readable, writable, and executable by the
user, readable and executable by the group and others, and allows its
user-ID to be assumed, during execution, by the user presently executing
it.
Another example of a file's permissions is:
-rw-rwL---
This describes a file that is readable and writable only by the user and
the group and can be locked during access.
An example of a command line:
ls -a
This command prints the names of all files in the current directory,
including those that begin with a dot (.), which normally do not print.
Another example of a command line:
ls -aisn
Page 5
ls(1) ls(1)
This command provides information on all files, including those that
begin with a dot (a), the i-number of the file printed in the left-hand
column (i); the size (in blocks) of the files, printed in the column to
the right of the i-numbers (s); finally, the report is displayed in the
numeric version of the long list, printing the UID (instead of user name)
and GID (instead of group name) numbers associated with the files.
When the sizes of the files in a directory are listed, a total count of
blocks, including indirect blocks, excluding holes, is printed.
/etc/passwd
user IDs for ls -l and ls -o
/etc/group
group IDs for ls -l and ls -g
/etc/mac
MAC label names for ls -M
/usr/lib/locale/locale<b>/LC_MESSAGES/uxcore.abi
language-specific message file [See LANG on environ (5).]
chmod(1), find(1) If the environment variable HUMAN_BLOCKS is set, it implies -h. If the
environment variable POSIXLY_CORRECT is set, ls processes exactly as
specified by the POSIX standeard. Unprintable characters in file names may confuse the columnar output
options.
The total block count will be incorrect if there are hard links among the
files.
PPPPaaaaggggeeee 6666 [ Back ]
|