LS(1) | General Commands Manual | LS(1) |
ls
— list
directory contents
ls |
[-@ABCFGHILOPRSTUWabcdefghiklmnopqrstuvwxy1%, ]
[--color =when]
[-D format]
[file ...] |
For each operand that names a file of a type
other than directory, ls
displays its name as well
as any requested, associated information. For each operand that names a
file of type directory, ls
displays the names of files contained within that directory, as well as any
requested, associated information.
If no operands are given, the contents of the current directory are displayed. If more than one operand is given, non-directory operands are displayed first; directory and non-directory operands are sorted separately and in lexicographical order.
The following options are available:
-@
-l
) output.-A
-I
is
specified.-B
\
xxx, where
xxx is the numeric value of the character in octal.
This option is not defined in IEEE Std 1003.1-2008
(“POSIX.1”).-C
-D
format-l
) format, use
format to format the date and time output. The
argument format is a string used by
strftime(3). Depending on the
choice of format string, this may result in a different number of columns
in the output. This option overrides the -T
option. This option is not defined in IEEE Std
1003.1-2008 (“POSIX.1”).-F
/
’) immediately
after each pathname that is a directory, an asterisk
(‘*
’) after each that is executable,
an at sign (‘@
’) after each symbolic
link, an equals sign (‘=
’) after
each socket, a percent sign (‘%
’)
after each whiteout, and a vertical bar
(‘|
’) after each that is a
FIFO.-G
CLICOLOR
or COLORTERM
in
the environment and setting
--color
=auto. (See below.)
This functionality can be compiled out by removing the definition of
COLORLS
. This option is not defined in
IEEE Std 1003.1-2008
(“POSIX.1”).-H
-F
, -d
, or
-l
options are specified.-I
-A
from being automatically set for the
super-user. This option is not defined in IEEE Std
1003.1-2008 (“POSIX.1”).-L
-P
option.-O
-l
) output. This
option is incompatible with IEEE Std 1003.1-2008
(“POSIX.1”). See
chflags(1) for a list of file flags
and their meanings.-P
-H
and -L
options.-R
-S
-T
-l
) format, display
complete time information for the file, including month, day, hour,
minute, second, and year. The -D
option gives even
more control over the output format. This option is not defined in
IEEE Std 1003.1-2008
(“POSIX.1”).-U
-W
-X
-a
-b
-B
, but use C escape codes whenever possible.
This option is not defined in IEEE Std 1003.1-2008
(“POSIX.1”).-c
--color
=whenalways
,
auto
, or never
.
always
will make
ls
always output color. If
TERM
is unset or set to an invalid terminal,
then ls
will fall back to explicit ANSI escape
sequences without the help of
termcap(5).
always
is the default if
--color
is specified without an argument.
auto
will make
ls
output escape sequences based on
termcap(5), but only if
stdout
is a tty and either the
-G
flag is specified or the
COLORTERM
environment variable is set and not
empty.
never
will disable color regardless of
environment variables. never
is the default when
neither --color
nor -G
is specified.
For compatibility with GNU coreutils,
ls
supports yes
or
force
as equivalent to
always
, no
or
none
as equivalent to
never
, and tty
or
if-tty
as equivalent to
auto
.
-d
-e
-l
) output.-f
-a
. It
also negates the effect of the -r
,
-S
and -t
options. As
allowed by IEEE Std 1003.1-2008
(“POSIX.1”), this option has no effect on the
-d
, -l
,
-R
and -s
options.-g
-l
) format output. This option
is incompatible with IEEE Std 1003.1-2008
(“POSIX.1”).-h
-l
option, use unit suffixes:
Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to
reduce the number of digits to four or fewer using base 2 for sizes. This
option is not defined in IEEE Std 1003.1-2008
(“POSIX.1”).-i
-k
BLOCKSIZE
to 1024, except that it also nullifies
any -h
options to its left.-l
-m
-n
-l
) output. This option
turns on the -l
option.-o
-p
/
’) after each
filename if that file is a directory.-q
?
’; this is the default when output
is to a terminal.-r
-s
-l
) format,
display complete time information for the file, including month, day,
hour, minute, second, and year. The -D
option
gives even more control over the output format. This option is not defined
in IEEE Std 1003.1-2008
(“POSIX.1”).-t
-r
option reverses both
of these sort orders.
Note that these sort orders are contradictory: the time
sequence is in descending order, the lexicographical sort is in
ascending order. This behavior is mandated by IEEE Std
1003.2 (“POSIX.2”). This feature can cause problems
listing files stored with sequential names on FAT file systems, such as
from digital cameras, where it is possible to have more than one image
with the same timestamp. In such a case, the photos cannot be listed in
the sequence in which they were taken. To ensure the same sort order for
time and for lexicographical sorting, set the environment variable
LS_SAMESORT
or use the
-y
option. This causes
ls
to reverse the lexicographical sort order
when sorting files with the same modification timestamp.
-u
-t
) or long printing
(-l
).-v
-w
-x
-C
, except that the multi-column
output is produced with entries sorted across, rather than down, the
columns.-y
-t
option is set, sort the alphabetical
output in the same order as the time output. This has the same effect as
setting LS_SAMESORT
. See the description of the
-t
option for more details. This option is not
defined in IEEE Std 1003.1-2001
(“POSIX.1”).-%
-l
) output, and don't materialize dataless
directories when listing them.-1
-
,-l
option is set, print file
sizes grouped and separated by thousands using the non-monetary separator
returned by localeconv(3),
typically a comma or period. If no locale is set, or the locale does not
have a non-monetary separator, this option has no effect. This option is
not defined in IEEE Std 1003.1-2001
(“POSIX.1”).The -1
, -C
,
-x
, and -l
options all
override each other; the last one specified determines the format used.
The -c
, -u
, and
-U
options all override each other; the last one
specified determines the file time used.
The -S
and -t
options override each other; the last one specified determines the sort
order used.
The -B
, -b
,
-w
, and -q
options all
override each other; the last one specified determines the format used for
non-printable characters.
The -H
, -L
and
-P
options all override each other (either partially
or fully); they are applied in the order specified.
By default, ls
lists one entry per line to
standard output; the exceptions are to terminals or when the
-C
or -x
options are
specified.
File information is displayed with one or more
⟨blank⟩s separating the information associated with the
-i
, -s
, and
-l
options.
If the -l
option is given, the following
information is displayed for each file: file mode, number of links, owner
name, group name, number of bytes in the file, abbreviated month,
day-of-month file was last modified, hour file last modified, minute file
last modified, and the pathname. If the file or directory has extended
attributes, the permissions field printed by the -l
option is followed by a '@' character. Otherwise, if the file or directory
has extended security information (such as an access control list), the
permissions field printed by the -l
option is
followed by a '+' character. If the -%
option is
given, a '%' character follows the permissions field for dataless files and
directories, possibly replacing the '@' or '+' character.
If the modification time of the file is more than 6 months in the
past or future, and the -D
or
-T
are not specified, then the year of the last
modification is displayed in place of the hour and minute fields.
If the owner or group names are not a known user or group name, or
the -n
option is given, the numeric ID's are
displayed.
If the file is a character special or block special file, the
device number for the file is displayed in the size field. If the file is a
symbolic link the pathname of the linked-to file is preceded by
“->
”.
The listing of a directory's contents is preceded by a labeled total number of blocks used in the file system by the files which are listed as the directory's contents (which may or may not include . and .. and other files which start with a dot, depending on other options).
The default block size is 512 bytes. The block size may be set
with option -k
or environment variable
BLOCKSIZE
. Numbers of blocks in the output will have
been rounded up so the numbers of bytes is at least as many as used by the
corresponding file system blocks (which might have a different size).
The file mode printed under the -l
option
consists of the entry type and the permissions. The entry type character
describes the type of file, as follows:
The next three fields are three characters each: owner permissions, group permissions, and other permissions. Each field has three character positions:
These next two apply only to the third character in the last group (other permissions).
The next field contains a plus
(‘+
’) character if the file has an
ACL, or a space (‘
’) if it does not.
The ls
utility does not show the actual ACL unless
the -e
option is used in conjunction with the
-l
option.
The following environment variables affect the execution of
ls
:
BLOCKSIZE
-l
and -s
options. See
The Long Format subsection for
more information.CLICOLOR
LSCOLORS
below. In addition to the file types
mentioned in the -F
option some extra attributes
(setuid bit set, etc.) are also displayed. The colorization is dependent
on a terminal type with the proper
termcap(5) capabilities. The default
“cons25
” console has the proper
capabilities, but to display the colors in an
xterm(1), for example, the
TERM
variable must be set to
“xterm-color
”. Other terminal types
may require similar adjustments. Colorization is silently disabled if the
output is not directed to a terminal unless the
CLICOLOR_FORCE
variable is defined or
--color
is set to “always”.CLICOLOR_FORCE
TERM
variable still needs to reference a color
capable terminal however otherwise it is not possible to determine which
color sequences to use.COLORTERM
CLICOLOR
above.COLUMNS
ls
utility calculates how many
pathname text columns to display based on the width provided. (See
-C
and -x
.)LANG
-l
format output. See
environ(7) for more
information.LSCOLORS
CLICOLOR
or
COLORTERM
. This string is a concatenation of pairs
of the format fb, where
f is the foreground color and
b is the background color.
The color designators are as follows:
Note that the above are standard ANSI colors. The actual display may differ depending on the color capabilities of the terminal in use.
The order of the attributes are as follows:
The default is "exfxcxdxbxegedabagacadah", i.e., blue foreground and default background for regular directories, black foreground and red background for setuid executables, etc.
LS_COLWIDTHS
LS_SAMESORT
-t
option sorts the
names of files with the same modification timestamp in the same sense as
the time sort. See the description of the -t
option for more details.TERM
CLICOLOR
and COLORTERM
functionality depends on a terminal type with color capabilities.TZ
The ls
utility exits 0 on success,
and >0 if an error occurs.
List the contents of the current working directory in long format:
$ ls -l
In addition to listing the contents of the current working directory in long format, show inode numbers, file flags (see chflags(1)), and suffix each filename with a symbol representing its file type:
$ ls -lioF
List the files in /var/log, sorting the output such that the most recently modified entries are printed first:
$ ls -lt /var/log
The group field is now automatically included in the long listing for files in order to be compatible with the IEEE Std 1003.2 (“POSIX.2”) specification.
In legacy mode, the -f
option does not
turn on the -a
option and the
-g
, -n
, and
-o
options do not turn on the
-l
option.
Also, the -o
option causes the file flags
to be included in a long (-l) output; there is no -O
option.
When -H
is specified (and not overridden
by -L
or -P
) and a file
argument is a symlink that resolves to a non-directory file, the output will
reflect the nature of the link, rather than that of the file. In legacy
operation, the output will describe the file.
For more information about legacy mode, see compat(5).
chflags(1), chmod(1), sort(1), xterm(1), localeconv(3), strftime(3), strmode(3), compat(5), termcap(5), sticky(7), symlink(7)
With the exception of options -g
,
-n
and -o
, the
ls
utility conforms to IEEE Std
1003.1-2001 (“POSIX.1”) and IEEE Std
1003.1-2008 (“POSIX.1”). The options
-B
, -D
,
-G
, -I
,
-T
, -U
,
-W
, -Z
,
-b
, -h
,
-w
, -y
and
-
, are non-standard extensions.
The ACL support is compatible with IEEE Std 1003.2c (“POSIX.2c”) Draft 17 (withdrawn).
An ls
command appeared in
Version 1 AT&T UNIX.
To maintain backward compatibility, the relationships between the many options are quite complex.
The exception mentioned in the -s
option
description might be a feature that was based on the fact that single-column
output usually goes to something other than a terminal. It is debatable
whether this is a design bug.
IEEE Std 1003.2 (“POSIX.2”)
mandates opposite sort orders for files with the same timestamp when sorting
with the -t
option.
August 31, 2020 | macOS 15.2 |