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