xref: /freebsd/bin/ls/ls.1 (revision 6780ab54325a71e7e70112b11657973edde8655e)
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 May 19, 2002
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 ABCFGHLPRTWZabcdfghiklmnopqrstuwx1
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.Pa \&.
76and
77.Pa .. .
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
83.Li \e Ns Va xxx ,
84where
85.Va xxx
86is the numeric value of the character in octal.
87.It Fl C
88Force multi-column output; this is the default when output is to a terminal.
89.It Fl F
90Display a slash
91.Pq Ql /
92immediately after each pathname that is a directory,
93an asterisk
94.Pq Ql *
95after each that is executable,
96an at sign
97.Pq Ql @
98after each symbolic link,
99an equals sign
100.Pq Ql =
101after each socket,
102a percent sign
103.Pq Ql %
104after each whiteout,
105and a vertical bar
106.Pq Ql \&|
107after each that is a
108.Tn FIFO .
109.It Fl G
110Enable colorized output.
111This option is equivalent to defining
112.Ev CLICOLOR
113in the environment.
114(See below.)
115.It Fl H
116Symbolic links on the command line are followed.
117This option is assumed if
118none of the
119.Fl F , d ,
120or
121.Fl l
122options are specified.
123.It Fl L
124If argument is a symbolic link, list the file or directory the link references
125rather than the link itself.
126This option cancels the
127.Fl P
128option.
129.It Fl P
130If argument is a symbolic link, list the link itself rather than the
131object the link references.
132This option cancels the
133.Fl H
134and
135.Fl L
136options.
137.It Fl R
138Recursively list subdirectories encountered.
139.It Fl T
140When used with the
141.Fl l
142(lowercase letter
143.Dq ell )
144option, display complete time information for the file, including
145month, day, hour, minute, second, and year.
146.It Fl W
147Display whiteouts when scanning directories.
148.It Fl Z
149Display each file's MAC label; see
150.Xr maclabel 7 .
151.It Fl a
152Include directory entries whose names begin with a
153dot
154.Pq Pa \&. .
155.It Fl b
156As
157.Fl B ,
158but use
159.Tn C
160escape codes whenever possible.
161.It Fl c
162Use time when file status was last changed for sorting or printing.
163.It Fl d
164Directories are listed as plain files (not searched recursively).
165.It Fl f
166Output is not sorted.
167.It Fl g
168This option is deprecated and is only available for compatibility
169with
170.Bx 4.3 ;
171it was used to display the group name in the long
172.Pq Fl l
173format output.
174.It Fl h
175When used with the
176.Fl l
177option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte
178and Petabyte in order to reduce the number of digits to three or less
179using base 2 for sizes.
180.It Fl i
181For each file, print the file's file serial number (inode number).
182.It Fl k
183If the
184.Fl s
185option is specified, print the file size allocation in kilobytes,
186not blocks.
187This option overrides the environment variable
188.Ev BLOCKSIZE .
189.It Fl l
190(The lowercase letter
191.Dq ell . )
192List in long format.
193(See below.)
194If the output is to a terminal, a total sum for all the file
195sizes is output on a line before the long listing.
196.It Fl m
197Stream output format; list files across the page, separated by commas.
198.It Fl n
199Display user and group IDs numerically rather than converting to a user
200or group name in a long
201.Pq Fl l
202output.
203.It Fl o
204Include the file flags in a long
205.Pq Fl l
206output.
207.It Fl p
208Write a slash
209.Pq Ql /
210after each filename if that file is a directory.
211.It Fl q
212Force printing of non-graphic characters in file names as
213the character
214.Ql \&? ;
215this is the default when output is to a terminal.
216.It Fl r
217Reverse the order of the sort to get reverse
218lexicographical order or the oldest entries first.
219.It Fl s
220Display the number of file system blocks actually used by each file, in units
221of 512 bytes, where partial units are rounded up to the next integer value.
222If the output is to a terminal, a total sum for all the file
223sizes is output on a line before the listing.
224The environment variable
225.Ev BLOCKSIZE
226overrides the unit size of 512 bytes.
227.It Fl t
228Sort by time modified (most recently modified
229first) before sorting the operands by lexicographical
230order.
231.It Fl u
232Use time of last access,
233instead of last modification
234of the file for sorting
235.Pq Fl t
236or printing
237.Pq Fl l .
238.It Fl w
239Force raw printing of non-printable characters.
240This is the default
241when output is not to a terminal.
242.It Fl x
243The same as
244.Fl C ,
245except that the multi-column output is produced with entries sorted
246across, rather than down, the columns.
247.It Fl 1
248(The numeric digit
249.Dq one . )
250Force output to be
251one entry per line.
252This is the default when
253output is not to a terminal.
254.El
255.Pp
256The
257.Fl 1 , C , x ,
258and
259.Fl l
260options all override each other; the last one specified determines
261the format used.
262.Pp
263The
264.Fl c
265and
266.Fl u
267options override each other; the last one specified determines
268the file time used.
269.Pp
270The
271.Fl B , b , w ,
272and
273.Fl q
274options all override each other; the last one specified determines
275the format used for non-printable characters.
276.Pp
277The
278.Fl H , L
279and
280.Fl P
281options all override each other (either partially or fully); they
282are applied in the order specified.
283.Pp
284By default,
285.Nm
286lists one entry per line to standard
287output; the exceptions are to terminals or when the
288.Fl C
289or
290.Fl x
291options are specified.
292.Pp
293File information is displayed with one or more
294.Ao blank Ac Ns s
295separating the information associated with the
296.Fl i , s ,
297and
298.Fl l
299options.
300.Ss The Long Format
301If the
302.Fl l
303option is given, the following information
304is displayed for each file:
305file mode,
306number of links, owner name, group name,
307MAC label,
308number of bytes in the file, abbreviated
309month, day-of-month file was last modified,
310hour file last modified, minute file last
311modified, and the pathname.
312In addition, for each directory whose contents are displayed, the total
313number of 512-byte blocks used by the files in the directory is displayed
314on a line by itself immediately before the information for the files in the
315directory.
316.Pp
317If the modification time of the file is more than 6 months
318in the past or future, then the year of the last modification
319is displayed in place of the hour and minute fields.
320.Pp
321If the owner or group names are not a known user or group name,
322or the
323.Fl n
324option is given,
325the numeric ID's are displayed.
326.Pp
327If the file is a character special or block special file,
328the major and minor device numbers for the file are displayed
329in the size field.
330If the file is a symbolic link the pathname of the
331linked-to file is preceded by
332.Dq Li -> .
333.Pp
334The file mode printed under the
335.Fl l
336option consists of the
337entry type, owner permissions, and group permissions.
338The entry type character describes the type of file, as
339follows:
340.Pp
341.Bl -tag -width 4n -offset indent -compact
342.It Sy b
343Block special file.
344.It Sy c
345Character special file.
346.It Sy d
347Directory.
348.It Sy l
349Symbolic link.
350.It Sy s
351Socket link.
352.It Sy p
353.Tn FIFO .
354.It Sy \-
355Regular file.
356.El
357.Pp
358The next three fields
359are three characters each:
360owner permissions,
361group permissions, and
362other permissions.
363Each field has three character positions:
364.Bl -enum -offset indent
365.It
366If
367.Sy r ,
368the file is readable; if
369.Sy \- ,
370it is not readable.
371.It
372If
373.Sy w ,
374the file is writable; if
375.Sy \- ,
376it is not writable.
377.It
378The first of the following that applies:
379.Bl -tag -width 4n -offset indent
380.It Sy S
381If in the owner permissions, the file is not executable and
382set-user-ID mode is set.
383If in the group permissions, the file is not executable
384and set-group-ID mode is set.
385.It Sy s
386If in the owner permissions, the file is executable
387and set-user-ID mode is set.
388If in the group permissions, the file is executable
389and setgroup-ID mode is set.
390.It Sy x
391The file is executable or the directory is
392searchable.
393.It Sy \-
394The file is neither readable, writable, executable,
395nor set-user-ID nor set-group-ID mode, nor sticky.
396(See below.)
397.El
398.Pp
399These next two apply only to the third character in the last group
400(other permissions).
401.Bl -tag -width 4n -offset indent
402.It Sy T
403The sticky bit is set
404(mode
405.Li 1000 ) ,
406but not execute or search permission.
407(See
408.Xr chmod 1
409or
410.Xr sticky 8 . )
411.It Sy t
412The sticky bit is set (mode
413.Li 1000 ) ,
414and is searchable or executable.
415(See
416.Xr chmod 1
417or
418.Xr sticky 8 . )
419.El
420.El
421.Pp
422The next field contains a
423plus
424.Pq Ql +
425character if the file has an ACL, or a
426space
427.Pq Ql " "
428if it does not.
429The
430.Nm
431utility does not show the actual ACL;
432use
433.Xr getfacl 1
434to do this.
435.Sh EXAMPLES
436The following is how to do an
437.Nm
438listing sorted by size (and shows why
439.Nm
440does not need a separate option for this):
441.Pp
442.Dl "ls -l | sort -n +4"
443.Pp
444Additionally, the
445.Fl r
446flag to
447.Xr sort 1
448may be used
449to get the results sorted from largest to smallest (a reverse sort).
450.Sh DIAGNOSTICS
451.Ex -std
452.Sh ENVIRONMENT
453The following environment variables affect the execution of
454.Nm :
455.Bl -tag -width ".Ev CLICOLOR_FORCE"
456.It Ev BLOCKSIZE
457If the environment variable
458.Ev BLOCKSIZE
459is set, the block counts
460(see
461.Fl s )
462will be displayed in units of that size block.
463.It Ev CLICOLOR
464Use
465.Tn ANSI
466color sequences to distinguish file types.
467See
468.Ev LSCOLORS
469below.
470In addition to the file types mentioned in the
471.Fl F
472option some extra attributes (setuid bit set, etc.) are also displayed.
473The colorization is dependent on a terminal type with the proper
474.Xr termcap 5
475capabilities.
476The default
477.Dq Li cons25
478console has the proper capabilities,
479but to display the colors in an
480.Xr xterm 1 ,
481for example,
482the
483.Ev TERM
484variable must be set to
485.Dq Li xterm-color .
486Other terminal types may require similar adjustments.
487Colorization
488is silently disabled if the output isn't directed to a terminal
489unless the
490.Ev CLICOLOR_FORCE
491variable is defined.
492.It Ev CLICOLOR_FORCE
493Color sequences are normally disabled if the output isn't directed to
494a terminal.
495This can be overridden by setting this flag.
496The
497.Ev TERM
498variable still needs to reference a color capable terminal however
499otherwise it is not possible to determine which color sequences to
500use.
501.It Ev COLUMNS
502If this variable contains a string representing a
503decimal integer, it is used as the
504column position width for displaying
505multiple-text-column output.
506The
507.Nm
508utility calculates how
509many pathname text columns to display
510based on the width provided.
511(See
512.Fl C
513and
514.Fl x . )
515.It Ev LANG
516The locale to use when determining the order of day and month in the long
517.Fl l
518format output.
519See
520.Xr environ 7
521for more information.
522.It Ev LSCOLORS
523The value of this variable describes what color to use for which
524attribute when colors are enabled with
525.Ev CLICOLOR .
526This string is a concatenation of pairs of the format
527.Ar f Ns Ar b ,
528where
529.Ar f
530is the foreground color and
531.Ar b
532is the background color.
533.Pp
534The color designators are as follows:
535.Pp
536.Bl -tag -width 4n -offset indent -compact
537.It Sy a
538black
539.It Sy b
540red
541.It Sy c
542green
543.It Sy d
544brown
545.It Sy e
546blue
547.It Sy f
548magenta
549.It Sy g
550cyan
551.It Sy h
552light grey
553.It Sy A
554bold black, usually shows up as dark grey
555.It Sy B
556bold red
557.It Sy C
558bold green
559.It Sy D
560bold brown, usually shows up as yellow
561.It Sy E
562bold blue
563.It Sy F
564bold magenta
565.It Sy G
566bold cyan
567.It Sy H
568bold light grey; looks like bright white
569.It Sy x
570default foreground or background
571.El
572.Pp
573Note that the above are standard
574.Tn ANSI
575colors.
576The actual display may differ
577depending on the color capabilities of the terminal in use.
578.Pp
579The order of the attributes are as follows:
580.Pp
581.Bl -enum -offset indent -compact
582.It
583directory
584.It
585symbolic link
586.It
587socket
588.It
589pipe
590.It
591executable
592.It
593block special
594.It
595character special
596.It
597executable with setuid bit set
598.It
599executable with setgid bit set
600.It
601directory writable to others, with sticky bit
602.It
603directory writable to others, without sticky bit
604.El
605.Pp
606The default is
607.Qq "exfxcxdxbxegedabagacad" ,
608i.e. blue foreground and
609default background for regular directories, black foreground and red
610background for setuid executables, etc.
611.It Ev LS_COLWIDTHS
612If this variable is set, it is considered to be a
613colon-delimited list of minimum column widths.
614Unreasonable
615and insufficient widths are ignored (thus zero signifies
616a dynamically sized column).
617Not all columns have changeable widths.
618The fields are,
619in order: inode, block count, number of links, user name,
620group name, flags, file size, file name.
621.It Ev TERM
622The
623.Ev CLICOLOR
624functionality depends on a terminal type with color capabilities.
625.It Ev TZ
626The timezone to use when displaying dates.
627See
628.Xr environ 7
629for more information.
630.El
631.Sh COMPATIBILITY
632The group field is now automatically included in the long listing for
633files in order to be compatible with the
634.St -p1003.2
635specification.
636.Sh SEE ALSO
637.Xr chflags 1 ,
638.Xr chmod 1 ,
639.Xr getfacl 1 ,
640.Xr sort 1 ,
641.Xr xterm 1 ,
642.Xr termcap 5 ,
643.Xr maclabel 7 ,
644.Xr symlink 7 ,
645.Xr getfmac 8 ,
646.Xr sticky 8
647.Sh STANDARDS
648The
649.Nm
650utility conforms to
651.St -p1003.1-2001 .
652.Pp
653The ACL support is compatible with
654.Tn IEEE
655Std\~1003.2c
656.Pq Dq Tn POSIX Ns .2c
657Draft\~17
658(withdrawn).
659.Sh HISTORY
660An
661.Nm
662command appeared in
663.At v1 .
664.Sh BUGS
665To maintain backward compatibility, the relationships between the many
666options are quite complex.
667