BSD options. | linux options are here |
For a file; display its name and attributes.
For a directory; displays the files in that directory and attributes.
If no operands are given, the contents of the current directory are displayed.
If more than one operand is given,
|
column formats -1, -C, -x,
and -l
override each other; the last one specified determines the format used.
-c
and -u
override each other; the last one specified determines the file time used.
-B, -b, -w,
and -q
override each other; the last one specified determines the format used for non-displayable characters.
code>-b As -B, but use C escape codes whenever possible.
-H, -L
and-P
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 blanks separating the information associated with the -i, -s, and -l options.
If the modification time of the file is more than 6 months away, the year is displayed instead of the hour and minutes.
If the owner or group names are not known (example they have been deleted), or
with -n
numeric ID's are displayed.
If the file is a character special or block special file, the major and minor device numbers for the file are displayed in the size field.
If the file is a symbolic link the pathname of the linked-to file is preceded by ->
The file mode displayed under the -l option consists of the entry type, owner permissions, and group permissions. The entry type character describes the type of file :
-
Regular file.
d
Directory.
l
Symbolic link.
b
Block special file.
c
Character special file.
s
Socket link.
p
FIFO.
Next, the permssion flags, are three fields of three characters each
(ex: rwxrwxr-x
) :
u
ser whos owns the file , g
roup members , and others. r
the file is readable; -
not readable. w
the file is writable; -
not writable. S
the file is not executable
s
the file is executable
x
file is executable or directory is searchable. -
file is neither readable, writable, executable, nor set-user-ID nor set-group-ID mode, nor sticky. T
sticky bit is set (mode 1000), but not execute or search permission. t
sticky bit is set (mode 1000), and is searchable or executable.
If the file or directory has extended security information, the permissions field is followed by a +
.
For directories the total number of 512-byte blocks used by the files in the directory is displayed on a line by itself immediately before the information for the files in the directory.
EXAMPLES
The following is how to do an ls listing sorted by size (and shows why ls does not need a separate
option for this):
ls -l | sort -n +4
-r
reverse sort order.
The ls utility exits 0 on success, and >0 if an error occurs.
ENVIRONMENT variables
BLOCKSIZE
the block counts will be displayed in units of that size block; default is 512.
CLICOLOR
Use ANSI color sequences to distinguish file types. See LSCOLORS.
In addition to the file types mentioned in -F
extra attributes (setuid bit set, etc.) are displayed. The colorization is dependent on a terminal type with the proper termcap(5) capabilities. The default cons25
console has the proper capabilities. To display the colors in an xterm, the TERM variable must be set to xterm‑color
. Other terminal types may require similar adjustments. Colorization is disabled if the output isn't directed to a terminal unless CLICOLOR_FORCE
is defined.
CLICOLOR_FORCE
if set, color sequences are output if not directed to a terminal.
COLUMNS
If this variable contains a string representing a decimal integer, it is used as the
column position width for displaying multiple-text-column output. The ls utility cal-
culates how many pathname text columns to display based on the width provided. (See -C
and -x.)
LSCOLORS
The value of this variable describes the colors used for which attribute when colors are enabled with CLICOLOR
.
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:
a black b red c green d brown e blue f magenta g cyan h light grey A bold black B bold red C bold green D bold brown, usually shows up as yellow E bold blue F bold magenta G bold cyan H bold light grey; looks like bright white x default foreground or background
The order of the attributes :
directory, symbolic link, socket, pipe, executable, block serial, character special, executable+SUID, executable+GUID, executabl+sticky+w=others, directory+w=others
The default is "exfxcxdxbxegedabagacad
",
i.e. blue foreground and default background
for regular directories, black foreground and red background for setuid executables,
etc.
LS_COLWIDTHS
a colon-delimited list of minimum column widths. Unreasonable and insufficient widths are ignored (thus zero signifies a dynamically sized column).
Not all columns have changeable widths.
inode, block count, number of links, user name, group name, flags, file size, file name.
TERM
The CLICOLOR functionality depends on a terminal type with color capabilities.
LANG
The locale to use when determining the order of day and month in the long -l
format output. See environ .
TZ
The timezone to use when displaying dates. See environ(7) for more information.
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.
SEE ALSO chflags(1), chmod(1), sort(1), xterm(1), compat(5), termcap(5), symlink(7), sticky(8)