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