xref: /freebsd/bin/ls/ls.1 (revision adeb92a24c57f97d5cd3c3c45be239cbb23aed68)
1.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgment:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"     @(#)ls.1	8.7 (Berkeley) 7/29/94
36.\" $FreeBSD$
37.\"
38.Dd July 29, 1994
39.Dt LS 1
40.Os
41.Sh NAME
42.Nm ls
43.Nd list directory contents
44.Sh SYNOPSIS
45.Nm
46.Op Fl ABCFGHLPRTWZabcdfghiklnoqrstuw1
47.Op Ar
48.Sh DESCRIPTION
49For each operand that names a
50.Ar file
51of a type other than
52directory,
53.Nm
54displays its name as well as any requested,
55associated information.
56For each operand that names a
57.Ar file
58of type directory,
59.Nm
60displays the names of files contained
61within that directory, as well as any requested, associated
62information.
63.Pp
64If no operands are given, the contents of the current
65directory are displayed.
66If more than one operand is given,
67non-directory operands are displayed first; directory
68and non-directory operands are sorted separately and in
69lexicographical order.
70.Pp
71The following options are available:
72.Bl -tag -width indent
73.It Fl A
74List all entries except for
75.Ql .\&
76and
77.Ql .. .
78Always set for the super-user.
79.It Fl B
80Force printing of non-printable characters (as defined by
81.Xr ctype 3
82and current locale settings) in file names as \\xxx,
83where xxx is the numeric value of the character in octal.
84.It Fl C
85Force multi-column output; this is the default when output is to a terminal.
86.It Fl F
87Display a slash (/) immediately after each pathname
88that is a directory, an asterisk (*) after each that is
89executable,
90an at sign (@) after each symbolic link,
91an equals sign (=) after each socket,
92a percent sign (%) after each whiteout,
93and a vertical bar (|) after each that is a
94.Tn FIFO .
95.It Fl G
96Enable colorized output.  This option is equivalent to defining
97.Ev CLICOLOR
98in the environment.  (See below).
99.It Fl H
100Symbolic links on the command line are followed.  This option is assumed if
101none of the
102.Fl F ,
103.Fl d ,
104or
105.Fl l
106options are specified.
107.It Fl L
108If argument is a symbolic link, list the file or directory the link references
109rather than the link itself.
110This option cancels the
111.Fl P
112option.
113.It Fl P
114If argument is a symbolic link, list the link itself rather than the
115object the link references.  This option cancels the
116.Fl H
117and
118.Fl L
119options.
120.It Fl R
121Recursively list subdirectories encountered.
122.It Fl T
123Display complete time information for the file, including
124month, day, hour, minute, second, and year.
125.It Fl W
126Display whiteouts when scanning directories.
127.It Fl Z
128Display each file's LOMAC level.
129.It Fl a
130Include directory entries whose names begin with a
131dot (.).
132.It Fl b
133As
134.Fl B ,
135but use C escape codes whenever possible.
136.It Fl c
137Use time when file status was last changed for sorting or printing.
138.It Fl d
139Directories are listed as plain files (not searched recursively).
140.It Fl f
141Output is not sorted.
142.It Fl g
143This option is deprecated and is only available for compatibility
144with
145.Bx 4.3 ;
146it was used to display the group name in the long
147.Pq Fl l
148format output.
149.It Fl h
150When used wih the
151.Fl l
152option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte
153and Petabyte in order to reduce the number of digits to three or less
154using base 2 for sizes.
155.It Fl i
156For each file, print the file's file serial number (inode number).
157.It Fl k
158If the
159.Fl s
160option is specified, print the file size allocation in kilobytes,
161not blocks.  This option overrides the environment variable BLOCKSIZE.
162.It Fl l
163(The lowercase letter ``ell.'')  List in long format.
164(See below.)
165If the output is to a terminal, a total sum for all the file
166sizes is output on a line before the long listing.
167.It Fl n
168Display user and group IDs numerically rather than converting to a user
169or group name in a long
170.Pq Fl l
171output.
172.It Fl o
173Include the file flags in a long
174.Pq Fl l
175output.
176.It Fl q
177Force printing of non-graphic characters in file names as
178the character `?'; this is the default when output is to a terminal.
179.It Fl r
180Reverse the order of the sort to get reverse
181lexicographical order or the oldest entries first.
182.It Fl s
183Display the number of file system blocks actually used by each file, in units
184of 512 bytes, where partial units are rounded up to the next integer value.
185If the output is to a terminal, a total sum for all the file
186sizes is output on a line before the listing.  The environment variable
187BLOCKSIZE overrides the unit size of 512 bytes.
188.It Fl t
189Sort by time modified (most recently modified
190first) before sorting the operands by lexicographical
191order.
192.It Fl u
193Use time of last access,
194instead of last modification
195of the file for sorting
196.Pq Fl t
197or printing
198.Pq Fl l .
199.It Fl w
200Force raw printing of non-printable characters.  This is the default
201when output is not to a terminal.
202.It Fl \&1
203(The numeric digit ``one.'')  Force output to be
204one entry per line.
205This is the default when
206output is not to a terminal.
207.El
208.Pp
209The
210.Fl 1 ,
211.Fl C ,
212and
213.Fl l
214options all override each other; the last one specified determines
215the format used.
216.Pp
217The
218.Fl c
219and
220.Fl u
221options override each other; the last one specified determines
222the file time used.
223.Pp
224The
225.Fl B ,
226.Fl b ,
227.Fl w ,
228and
229.Fl q
230options all override each other; the last one specified determines
231the format used for non-printable characters.
232.Pp
233The
234.Fl H ,
235.Fl L
236and
237.Fl P
238options all override each other (either partially or fully); they
239are applied in the order specified.
240.Pp
241By default,
242.Nm
243lists one entry per line to standard
244output; the exceptions are to terminals or when the
245.Fl C
246option is specified.
247.Pp
248File information is displayed with one or more
249<blank>s separating the information associated with the
250.Fl i ,
251.Fl s ,
252and
253.Fl l
254options.
255.Ss The Long Format
256If the
257.Fl l
258option is given, the following information
259is displayed for each file:
260file mode,
261number of links, owner name, group name,
262LOMAC level,
263number of bytes in the file, abbreviated
264month, day-of-month file was last modified,
265hour file last modified, minute file last
266modified, and the pathname.
267In addition, for each directory whose contents are displayed, the total
268number of 512-byte blocks used by the files in the directory is displayed
269on a line by itself immediately before the information for the files in the
270directory.
271.Pp
272If the modification time of the file is more than 6 months
273in the past or future, then the year of the last modification
274is displayed in place of the hour and minute fields.
275.Pp
276If the owner or group names are not a known user or group name,
277or the
278.Fl n
279option is given,
280the numeric ID's are displayed.
281.Pp
282If the file is a character special or block special file,
283the major and minor device numbers for the file are displayed
284in the size field.
285If the file is a symbolic link the pathname of the
286linked-to file is preceded by
287.Dq \-> .
288.Pp
289The file mode printed under the
290.Fl l
291option consists of the
292entry type, owner permissions, and group permissions.
293The entry type character describes the type of file, as
294follows:
295.Pp
296.Bl -tag -width 4n -offset indent -compact
297.It Sy b
298Block special file.
299.It Sy c
300Character special file.
301.It Sy d
302Directory.
303.It Sy l
304Symbolic link.
305.It Sy s
306Socket link.
307.It Sy p
308.Tn FIFO .
309.It Sy \-
310Regular file.
311.El
312.Pp
313The next three fields
314are three characters each:
315owner permissions,
316group permissions, and
317other permissions.
318Each field has three character positions:
319.Bl -enum -offset indent
320.It
321If
322.Sy r ,
323the file is readable; if
324.Sy \- ,
325it is not readable.
326.It
327If
328.Sy w ,
329the file is writable; if
330.Sy \- ,
331it is not writable.
332.It
333The first of the following that applies:
334.Bl -tag -width 4n -offset indent
335.It Sy S
336If in the owner permissions, the file is not executable and
337set-user-ID mode is set.
338If in the group permissions, the file is not executable
339and set-group-ID mode is set.
340.It Sy s
341If in the owner permissions, the file is executable
342and set-user-ID mode is set.
343If in the group permissions, the file is executable
344and setgroup-ID mode is set.
345.It Sy x
346The file is executable or the directory is
347searchable.
348.It Sy \-
349The file is neither readable, writable, executable,
350nor set-user-ID nor set-group-ID mode, nor sticky.
351(See below.)
352.El
353.Pp
354These next two apply only to the third character in the last group
355(other permissions).
356.Bl -tag -width 4n -offset indent
357.It Sy T
358The sticky bit is set
359(mode
360.Li 1000 ) ,
361but not execute or search permission.
362(See
363.Xr chmod 1
364or
365.Xr sticky 8 . )
366.It Sy t
367The sticky bit is set (mode
368.Li 1000 ) ,
369and is searchable or executable.
370(See
371.Xr chmod 1
372or
373.Xr sticky 8 . )
374.El
375.El
376.Sh EXAMPLES
377The following is how to do an
378.Nm
379listing sorted by size (and shows why
380.Nm
381does not need a separate option for this):
382.Pp
383.Dl "ls -l | sort -n +4"
384.Pp
385Additionally, the
386.Fl r
387flag to
388.Xr sort 1
389may be used
390to get the results sorted from largest to smallest (a reverse sort).
391.Sh DIAGNOSTICS
392.Ex -std
393.Sh ENVIRONMENT
394The following environment variables affect the execution of
395.Nm :
396.Bl -tag -width BLOCKSIZE
397.It Ev BLOCKSIZE
398If the environment variable
399.Ev BLOCKSIZE
400is set, the block counts
401(see
402.Fl s )
403will be displayed in units of that size block.
404.It Ev CLICOLOR
405Use
406.Tn ANSI
407color sequences to distinguish file types.
408See
409.Ev LSCOLORS
410below.
411In addition to the file types mentioned in the
412.Fl F
413option some extra attributes (setuid bit set, etc.) are also displayed.
414The colorization is dependent on a terminal type with the proper
415.Xr termcap 5
416capabilities.
417The default
418.Dq cons25
419console has the proper capabilities,
420but to display the colors in an
421.Xr xterm 1 ,
422for example,
423the
424.Ev TERM
425variable must be set to
426.Dq xterm-color .
427Other terminal types may require similar adjustments.  Colorization
428is silently disabled if the output isn't directed to a terminal
429unless the
430.Ev CLICOLOR_FORCE
431variable is defined.
432.It Ev CLICOLOR_FORCE
433Color sequences are normally disabled if the output isn't directed to
434a terminal.  This can be overridden by setting this flag.
435The
436.Ev TERM
437variable still needs to reference a color capable terminal however
438otherwise it is not possible to determine which color sequences to
439use.
440.It Ev COLUMNS
441If this variable contains a string representing a
442decimal integer, it is used as the
443column position width for displaying
444multiple-text-column output.
445The
446.Nm
447utility calculates how
448many pathname text columns to display
449based on the width provided.
450(See
451.Fl C . )
452.It Ev LANG
453The locale to use when determining the order of day and month in the long
454.Fl l
455format output.
456See
457.Xr environ 7
458for more information.
459.It Ev LSCOLORS
460The value of this variable describes what color to use for which
461attribute when colors are enabled with
462.Ev CLICOLOR .
463This string is a concatenation of pairs of the format
464.Sy fb ,
465where
466.Sy f
467is the foreground color and
468.Sy b
469is the background color.
470.Pp
471The color designators are as follows:
472.Pp
473.Bl -tag -width 4n -offset indent -compact
474.It Sy a
475black
476.It Sy b
477red
478.It Sy c
479green
480.It Sy d
481brown
482.It Sy e
483blue
484.It Sy f
485magenta
486.It Sy g
487cyan
488.It Sy h
489light grey
490.It Sy A
491bold black, usually shows up as dark grey
492.It Sy B
493bold red
494.It Sy C
495bold green
496.It Sy D
497bold brown, usually shows up as yellow
498.It Sy E
499bold blue
500.It Sy F
501bold magenta
502.It Sy G
503bold cyan
504.It Sy H
505bold light grey; looks like bright white
506.It Sy x
507default foreground or background
508.El
509.Pp
510Note that the above are standard
511.Tn ANSI
512colors.
513The actual display may differ
514depending on the color capabilities of the terminal in use.
515.Pp
516The order of the attributes are as follows:
517.Pp
518.Bl -enum -offset indent -compact
519.It
520directory
521.It
522symbolic link
523.It
524socket
525.It
526pipe
527.It
528executable
529.It
530block special
531.It
532character special
533.It
534executable with setuid bit set
535.It
536executable with setgid bit set
537.It
538directory writable to others, with sticky bit
539.It
540directory writable to others, without sticky bit
541.El
542.Pp
543The default is "exfxcxdxbxegedabagacad", i.e. blue foreground and
544default background for regular directories, black foreground and red
545background for setuid executables, etc.
546.It Ev LS_COLWIDTHS
547If this variable is set, it is considered to be a
548colon-delimited list of minimum column widths.  Unreasonable
549and insufficient widths are ignored (thus zero signifies
550a dynamically sized column).  Not all
551columns have changeable widths.  The fields are,
552in order: inode, block count, number of links, user name,
553group name, flags, file size, file name.
554.It Ev TERM
555The
556.Ev CLICOLOR
557functionality depends on a terminal type with color capabilities.
558.It Ev TZ
559The timezone to use when displaying dates.
560See
561.Xr environ 7
562for more information.
563.El
564.Sh COMPATIBILITY
565The group field is now automatically included in the long listing for
566files in order to be compatible with the
567.St -p1003.2
568specification.
569.Sh FILES
570.Bl -tag -width ".Pa /dev/lomac" -compact
571.It Pa /dev/lomac
572interface used to query the
573.Xr lomac 4
574KLD
575.El
576.Sh SEE ALSO
577.Xr chflags 1 ,
578.Xr chmod 1 ,
579.Xr sort 1 ,
580.Xr xterm 1 ,
581.Xr lomac 4 ,
582.Xr termcap 5 ,
583.Xr symlink 7 ,
584.Xr sticky 8
585.Sh HISTORY
586An
587.Nm
588command appeared in
589.At v1 .
590.Sh STANDARDS
591The
592.Nm
593function is expected to be a superset of the
594.St -p1003.2
595specification.
596.Sh BUGS
597To maintain backward compatibility, the relationships between the many
598options are quite complex.
599