ls - (BSD) list contents of directory
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 no argument is
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. There are several options:
- List all entries; usually files that begin with a `.' are
- List all entries except `.' and `..'. This is default if
ls is invoked by the super-user.
- Use time of last modification to inode (mode, etc.) instead of last
modification to file for sorting (-t) or printing (-l).
- Output is printed in multiple columns, sorted down the columns. This
format is selected by default if standard output refers to a
- If argument is a directory, list only its name, not its contents (mostly
used with -l to get status on directory).
- 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.
- Indicates the file type as a letter appended to each pathname:
- If combined with -l, the group ID is added to the output.
- Print i-number in first column of the report for each file listed.
- List in long format, giving mode, number of links, owner, size in bytes,
and time of last modification for each file. (See below.) If the file is a
special file the size field will instead contain the major and minor
device numbers. Symbolic links specified as arguments are not followed
with this option unless the -H or -L option is also
- Follow symbolic links in arguments.
- Non-printable characters are printed as question marks `?'. This is
the default if standard output refers to a terminal.
- Reverse the order of sort to get reverse alphabetic or oldest first as
- Lists subdirectories recursively.
- Give size in blocks, including indirect blocks, for each entry.
- Sort by time modified (latest first) instead of by name, as is
- Use time of last access instead of last modification for sorting
(-t) or printing (-l).
- Print one filename per output line. This is the default if standard output
does not refer to a terminal.
The following option was introduced with POSIX.1-2001:
- Follow symbolic links given as arguments.
The following options are available as extensions:
- Print file sizes in human-readable powers of 1024, i.e. `K' for kilobyte,
`M' for megabyte, `G' for gigabyte, `T' for terabyte, `P' for petabyte,
and `E' for exabyte.
- Sort by file size.
- Do not sort at all.
- Sort by file name extension, i.e. by the component of the file name
following the last dot.
The mode printed under the -l
option contains 10 characters which are
interpreted as follows: the first character is
||if the entry is a directory;
||if the entry is a block-type special file;
||if the entry is a character-type special file;
||if the entry is a named pipe;
||if the entry is a symbolic link;
||if the entry is a socket;
||if the entry is a XENIX semaphore;
||if the entry is a XENIX shared data (memory) file;
||if the entry is a door;
||if the entry is a plain file.
The next 9 characters are interpreted as three sets of three bits each. The
first set refers to owner permissions; the next to permissions to others in
the same user-group; and the last to all others. Within each set the three
characters indicate permission respectively to read, to write, or to execute
the file as a program. For a directory, `execute' permission is interpreted to
mean permission to search the directory for a specified file. The permissions
are indicated as follows:
||if the file is readable;
||if the file is writable;
||if the file is executable;
||if the indicated permission is not granted.
The group-execute permission character is given as
||if the file has set-group-ID mode;
||if the set-group-ID bit is set on the file but it is not
Likewise the user-execute permission character is given as
||if the file has set-user-ID mode;
||if the set-user-ID bit is set on the file but it is not executable.
The last character of the mode (normally `x' or `-') is
||if the sticky bit of the mode is on;
||if the sticky bit is on but the file is not executable.
(1) for the meaning of this mode.
When the sizes of the files in a directory are listed, a total count of blocks,
including indirect blocks is printed.
writes its output to a terminal that supports colors or boldface,
file names printed are colorized according to their types:
||if the file is a directory;
||if the file is a special file;
||if the file is a named pipe;
||if the file is a symbolic link;
||if the file is a socket or a door;
||if the file is a XENIX special file;
||if the file is executable.
, colors are enabled even if the output is not written to a
terminal. This is mainly useful if the output is filtered through a pager
which handles colors, such as pg
- to get user IDs.
- to get group IDs.
- Overrides the auto-detected terminal width.
- LANG, LC_ALL
- See locale(7).
- Affects the order of printed items when sorting by name.
- Determines whether a character is printable.
- Sets the format of time strings printed with the -l option.
- Used to determine the terminal type.