xref: /freebsd/bin/ls/ls.1 (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1.\"-
2.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
3.\"	The Regents of the University of California.  All rights reserved.
4.\"
5.\" This code is derived from software contributed to Berkeley by
6.\" the Institute of Electrical and Electronics Engineers, Inc.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)ls.1	8.7 (Berkeley) 7/29/94
33.\" $FreeBSD$
34.\"
35.Dd December 1, 2015
36.Dt LS 1
37.Os
38.Sh NAME
39.Nm ls
40.Nd list directory contents
41.Sh SYNOPSIS
42.Nm
43.Op Fl -libxo
44.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,
45.Op Fl D Ar format
46.Op Ar
47.Sh DESCRIPTION
48For each operand that names a
49.Ar file
50of a type other than
51directory,
52.Nm
53displays its name as well as any requested,
54associated information.
55For each operand that names a
56.Ar file
57of type directory,
58.Nm
59displays the names of files contained
60within that directory, as well as any requested, associated
61information.
62.Pp
63If no operands are given, the contents of the current
64directory are displayed.
65If more than one operand is given,
66non-directory operands are displayed first; directory
67and non-directory operands are sorted separately and in
68lexicographical order.
69.Pp
70The following options are available:
71.Bl -tag -width indent
72.It Fl -libxo
73Generate output via
74.Xr libxo 3
75in a selection of different human and machine readable formats.
76See
77.Xr xo_parse_args 3
78for details on command line arguments.
79.It Fl A
80Include directory entries whose names begin with a
81dot
82.Pq Sq Pa \&.
83except for
84.Pa \&.
85and
86.Pa .. .
87Automatically set for the super-user unless
88.Fl I
89is specified.
90.It Fl B
91Force printing of non-printable characters (as defined by
92.Xr ctype 3
93and current locale settings) in file names as
94.Li \e Ns Va xxx ,
95where
96.Va xxx
97is the numeric value of the character in octal.
98This option is not defined in
99.St -p1003.1-2001 .
100.It Fl C
101Force multi-column output; this is the default when output is to a terminal.
102.It Fl D Ar format
103When printing in the long
104.Pq Fl l
105format, use
106.Ar format
107to format the date and time output.
108The argument
109.Ar format
110is a string used by
111.Xr strftime 3 .
112Depending on the choice of format string, this may result in a
113different number of columns in the output.
114This option overrides the
115.Fl T
116option.
117This option is not defined in
118.St -p1003.1-2001 .
119.It Fl F
120Display a slash
121.Pq Ql /
122immediately after each pathname that is a directory,
123an asterisk
124.Pq Ql *
125after each that is executable,
126an at sign
127.Pq Ql @
128after each symbolic link,
129an equals sign
130.Pq Ql =
131after each socket,
132a percent sign
133.Pq Ql %
134after each whiteout,
135and a vertical bar
136.Pq Ql \&|
137after each that is a
138.Tn FIFO .
139.It Fl G
140Enable colorized output.
141This option is equivalent to defining
142.Ev CLICOLOR
143in the environment.
144(See below.)
145This functionality can be compiled out by removing the definition of
146.Ev COLORLS .
147This option is not defined in
148.St -p1003.1-2001 .
149.It Fl H
150Symbolic links on the command line are followed.
151This option is assumed if
152none of the
153.Fl F , d ,
154or
155.Fl l
156options are specified.
157.It Fl I
158Prevent
159.Fl A
160from being automatically set for the super-user.
161This option is not defined in
162.St -p1003.1-2001 .
163.It Fl L
164If argument is a symbolic link, list the file or directory the link references
165rather than the link itself.
166This option cancels the
167.Fl P
168option.
169.It Fl P
170If argument is a symbolic link, list the link itself rather than the
171object the link references.
172This option cancels the
173.Fl H
174and
175.Fl L
176options.
177.It Fl R
178Recursively list subdirectories encountered.
179.It Fl S
180Sort by size (largest file first) before sorting the operands in
181lexicographical order.
182.It Fl T
183When printing in the long
184.Pq Fl l
185format, display complete time information for the file, including
186month, day, hour, minute, second, and year.
187The
188.Fl D
189option gives even more control over the output format.
190This option is not defined in
191.St -p1003.1-2001 .
192.It Fl U
193Use time when file was created for sorting or printing.
194This option is not defined in
195.St -p1003.1-2001 .
196.It Fl W
197Display whiteouts when scanning directories.
198This option is not defined in
199.St -p1003.1-2001 .
200.It Fl Z
201Display each file's MAC label; see
202.Xr maclabel 7 .
203This option is not defined in
204.St -p1003.1-2001 .
205.It Fl a
206Include directory entries whose names begin with a
207dot
208.Pq Sq Pa \&. .
209.It Fl b
210As
211.Fl B ,
212but use
213.Tn C
214escape codes whenever possible.
215This option is not defined in
216.St -p1003.1-2001 .
217.It Fl c
218Use time when file status was last changed for sorting or printing.
219.It Fl d
220Directories are listed as plain files (not searched recursively).
221.It Fl f
222Output is not sorted.
223This option turns on
224.Fl a .
225It also negates the effect of the
226.Fl r ,
227.Fl S
228and
229.Fl t
230options.
231As allowed by
232.St -p1003.1-2001 ,
233this option has no effect on the
234.Fl d ,
235.Fl l ,
236.Fl R
237and
238.Fl s
239options.
240.It Fl g
241This option has no effect.
242It is only available for compatibility with
243.Bx 4.3 ,
244where it was used to display the group name in the long
245.Pq Fl l
246format output.
247This option is incompatible with
248.St -p1003.1-2001 .
249.It Fl h
250When used with the
251.Fl l
252option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte
253and Petabyte in order to reduce the number of digits to four or fewer
254using base 2 for sizes.
255This option is not defined in
256.St -p1003.1-2001 .
257.It Fl i
258For each file, print the file's file serial number (inode number).
259.It Fl k
260This has the same effect as setting environment variable
261.Ev BLOCKSIZE
262to 1024, except that it also nullifies any
263.Fl h
264options to its left.
265.It Fl l
266(The lowercase letter
267.Dq ell . )
268List files in the long format, as described in the
269.Sx The Long Format
270subsection below.
271.It Fl m
272Stream output format; list files across the page, separated by commas.
273.It Fl n
274Display user and group IDs numerically rather than converting to a user
275or group name in a long
276.Pq Fl l
277output.
278.It Fl o
279Include the file flags in a long
280.Pq Fl l
281output.
282This option is incompatible with
283.St -p1003.1-2001 .
284See
285.Xr chflags 1
286for a list of file flags and their meanings.
287.It Fl p
288Write a slash
289.Pq Ql /
290after each filename if that file is a directory.
291.It Fl q
292Force printing of non-graphic characters in file names as
293the character
294.Ql \&? ;
295this is the default when output is to a terminal.
296.It Fl r
297Reverse the order of the sort.
298.It Fl s
299Display the number of blocks used in the file system by each file.
300Block sizes and directory totals are handled as described in
301.Sx The Long Format
302subsection below, except (if the long format is not also requested)
303the directory totals are not output when the output is in a
304single column, even if multi-column output is requested.
305.It Fl t
306Sort by descending time modified (most recently modified first).
307If two files have the same modification timestamp, sort their names
308in ascending lexicographical order.
309The
310.Fl r
311option reverses both of these sort orders.
312.Pp
313Note that these sort orders are contradictory: the time sequence is in
314descending order, the lexicographical sort is in ascending order.
315This behavior is mandated by
316.St -p1003.2 .
317This feature can cause problems listing files stored with sequential names on
318FAT file systems, such as from digital cameras, where it is possible to have
319more than one image with the same timestamp.
320In such a case, the photos cannot be listed in the sequence in which
321they were taken.
322To ensure the same sort order for time and for lexicographical sorting, set the
323environment variable
324.Ev LS_SAMESORT
325or use the
326.Fl y
327option.
328This causes
329.Nm
330to reverse the lexicographical sort order when sorting files with the
331same modification timestamp.
332.It Fl u
333Use time of last access,
334instead of time of last modification
335of the file for sorting
336.Pq Fl t
337or printing
338.Pq Fl l .
339.It Fl w
340Force raw printing of non-printable characters.
341This is the default
342when output is not to a terminal.
343This option is not defined in
344.St -p1003.1-2001 .
345.It Fl x
346The same as
347.Fl C ,
348except that the multi-column output is produced with entries sorted
349across, rather than down, the columns.
350.It Fl y
351When the
352.Fl t
353option is set, sort the alphabetical output in the same order as the time output.
354This has the same effect as setting
355.Ev LS_SAMESORT .
356See the description of the
357.Fl t
358option for more details.
359This option is not defined in
360.St -p1003.1-2001 .
361.It Fl 1
362(The numeric digit
363.Dq one . )
364Force output to be
365one entry per line.
366This is the default when
367output is not to a terminal.
368.It Fl ,
369(Comma) When the
370.Fl l
371option is set, print file sizes grouped and separated by thousands using the
372non-monetary separator returned by
373.Xr localeconv 3 ,
374typically a comma or period.
375If no locale is set, or the locale does not have a non-monetary separator, this
376option has no effect.
377This option is not defined in
378.St -p1003.1-2001 .
379.El
380.Pp
381The
382.Fl 1 , C , x ,
383and
384.Fl l
385options all override each other; the last one specified determines
386the format used.
387.Pp
388The
389.Fl c , u ,
390and
391.Fl U
392options all override each other; the last one specified determines
393the file time used.
394.Pp
395The
396.Fl S
397and
398.Fl t
399options override each other; the last one specified determines
400the sort order used.
401.Pp
402The
403.Fl B , b , w ,
404and
405.Fl q
406options all override each other; the last one specified determines
407the format used for non-printable characters.
408.Pp
409The
410.Fl H , L
411and
412.Fl P
413options all override each other (either partially or fully); they
414are applied in the order specified.
415.Pp
416By default,
417.Nm
418lists one entry per line to standard
419output; the exceptions are to terminals or when the
420.Fl C
421or
422.Fl x
423options are specified.
424.Pp
425File information is displayed with one or more
426.Ao blank Ac Ns s
427separating the information associated with the
428.Fl i , s ,
429and
430.Fl l
431options.
432.Ss The Long Format
433If the
434.Fl l
435option is given, the following information
436is displayed for each file:
437file mode,
438number of links, owner name, group name,
439MAC label,
440number of bytes in the file, abbreviated
441month, day-of-month file was last modified,
442hour file last modified, minute file last
443modified, and the pathname.
444.Pp
445If the modification time of the file is more than 6 months
446in the past or future, and the
447.Fl D
448or
449.Fl T
450are not specified,
451then the year of the last modification
452is displayed in place of the hour and minute fields.
453.Pp
454If the owner or group names are not a known user or group name,
455or the
456.Fl n
457option is given,
458the numeric ID's are displayed.
459.Pp
460If the file is a character special or block special file,
461the device number for the file is displayed in the size field.
462If the file is a symbolic link the pathname of the
463linked-to file is preceded by
464.Dq Li -> .
465.Pp
466The listing of a directory's contents is preceded
467by a labeled total number of blocks used in the file system by the files
468which are listed as the directory's contents
469(which may or may not include
470.Pa \&.
471and
472.Pa ..
473and other files which start with a dot, depending on other options).
474.Pp
475The default block size is 512 bytes.
476The block size may be set with option
477.Fl k
478or environment variable
479.Ev BLOCKSIZE .
480Numbers of blocks in the output will have been rounded up so the
481numbers of bytes is at least as many as used by the corresponding
482file system blocks (which might have a different size).
483.Pp
484The file mode printed under the
485.Fl l
486option consists of the
487entry type and the permissions.
488The entry type character describes the type of file, as
489follows:
490.Pp
491.Bl -tag -width 4n -offset indent -compact
492.It Sy \-
493Regular file.
494.It Sy b
495Block special file.
496.It Sy c
497Character special file.
498.It Sy d
499Directory.
500.It Sy l
501Symbolic link.
502.It Sy p
503.Tn FIFO .
504.It Sy s
505Socket.
506.It Sy w
507Whiteout.
508.El
509.Pp
510The next three fields
511are three characters each:
512owner permissions,
513group permissions, and
514other permissions.
515Each field has three character positions:
516.Bl -enum -offset indent
517.It
518If
519.Sy r ,
520the file is readable; if
521.Sy \- ,
522it is not readable.
523.It
524If
525.Sy w ,
526the file is writable; if
527.Sy \- ,
528it is not writable.
529.It
530The first of the following that applies:
531.Bl -tag -width 4n -offset indent
532.It Sy S
533If in the owner permissions, the file is not executable and
534set-user-ID mode is set.
535If in the group permissions, the file is not executable
536and set-group-ID mode is set.
537.It Sy s
538If in the owner permissions, the file is executable
539and set-user-ID mode is set.
540If in the group permissions, the file is executable
541and setgroup-ID mode is set.
542.It Sy x
543The file is executable or the directory is
544searchable.
545.It Sy \-
546The file is neither readable, writable, executable,
547nor set-user-ID nor set-group-ID mode, nor sticky.
548(See below.)
549.El
550.Pp
551These next two apply only to the third character in the last group
552(other permissions).
553.Bl -tag -width 4n -offset indent
554.It Sy T
555The sticky bit is set
556(mode
557.Li 1000 ) ,
558but not execute or search permission.
559(See
560.Xr chmod 1
561or
562.Xr sticky 7 . )
563.It Sy t
564The sticky bit is set (mode
565.Li 1000 ) ,
566and is searchable or executable.
567(See
568.Xr chmod 1
569or
570.Xr sticky 7 . )
571.El
572.El
573.Pp
574The next field contains a
575plus
576.Pq Ql +
577character if the file has an ACL, or a
578space
579.Pq Ql " "
580if it does not.
581The
582.Nm
583utility does not show the actual ACL;
584use
585.Xr getfacl 1
586to do this.
587.Sh ENVIRONMENT
588The following environment variables affect the execution of
589.Nm :
590.Bl -tag -width ".Ev CLICOLOR_FORCE"
591.It Ev BLOCKSIZE
592If this is set, its value, rounded up to 512 or down to a
593multiple of 512, will be used as the block size in bytes by the
594.Fl l
595and
596.Fl s
597options.
598See
599.Sx The Long Format
600subsection for more information.
601.It Ev CLICOLOR
602Use
603.Tn ANSI
604color sequences to distinguish file types.
605See
606.Ev LSCOLORS
607below.
608In addition to the file types mentioned in the
609.Fl F
610option some extra attributes (setuid bit set, etc.) are also displayed.
611The colorization is dependent on a terminal type with the proper
612.Xr termcap 5
613capabilities.
614The default
615.Dq Li cons25
616console has the proper capabilities,
617but to display the colors in an
618.Xr xterm 1 ,
619for example,
620the
621.Ev TERM
622variable must be set to
623.Dq Li xterm-color .
624Other terminal types may require similar adjustments.
625Colorization
626is silently disabled if the output is not directed to a terminal
627unless the
628.Ev CLICOLOR_FORCE
629variable is defined.
630.It Ev CLICOLOR_FORCE
631Color sequences are normally disabled if the output is not directed to
632a terminal.
633This can be overridden by setting this variable.
634The
635.Ev TERM
636variable still needs to reference a color capable terminal however
637otherwise it is not possible to determine which color sequences to
638use.
639.It Ev COLUMNS
640If this variable contains a string representing a
641decimal integer, it is used as the
642column position width for displaying
643multiple-text-column output.
644The
645.Nm
646utility calculates how
647many pathname text columns to display
648based on the width provided.
649(See
650.Fl C
651and
652.Fl x . )
653.It Ev LANG
654The locale to use when determining the order of day and month in the long
655.Fl l
656format output.
657See
658.Xr environ 7
659for more information.
660.It Ev LSCOLORS
661The value of this variable describes what color to use for which
662attribute when colors are enabled with
663.Ev CLICOLOR .
664This string is a concatenation of pairs of the format
665.Ar f Ns Ar b ,
666where
667.Ar f
668is the foreground color and
669.Ar b
670is the background color.
671.Pp
672The color designators are as follows:
673.Pp
674.Bl -tag -width 4n -offset indent -compact
675.It Sy a
676black
677.It Sy b
678red
679.It Sy c
680green
681.It Sy d
682brown
683.It Sy e
684blue
685.It Sy f
686magenta
687.It Sy g
688cyan
689.It Sy h
690light grey
691.It Sy A
692bold black, usually shows up as dark grey
693.It Sy B
694bold red
695.It Sy C
696bold green
697.It Sy D
698bold brown, usually shows up as yellow
699.It Sy E
700bold blue
701.It Sy F
702bold magenta
703.It Sy G
704bold cyan
705.It Sy H
706bold light grey; looks like bright white
707.It Sy x
708default foreground or background
709.El
710.Pp
711Note that the above are standard
712.Tn ANSI
713colors.
714The actual display may differ
715depending on the color capabilities of the terminal in use.
716.Pp
717The order of the attributes are as follows:
718.Pp
719.Bl -enum -offset indent -compact
720.It
721directory
722.It
723symbolic link
724.It
725socket
726.It
727pipe
728.It
729executable
730.It
731block special
732.It
733character special
734.It
735executable with setuid bit set
736.It
737executable with setgid bit set
738.It
739directory writable to others, with sticky bit
740.It
741directory writable to others, without sticky bit
742.El
743.Pp
744The default is
745.Qq "exfxcxdxbxegedabagacad" ,
746i.e., blue foreground and
747default background for regular directories, black foreground and red
748background for setuid executables, etc.
749.It Ev LS_COLWIDTHS
750If this variable is set, it is considered to be a
751colon-delimited list of minimum column widths.
752Unreasonable
753and insufficient widths are ignored (thus zero signifies
754a dynamically sized column).
755Not all columns have changeable widths.
756The fields are,
757in order: inode, block count, number of links, user name,
758group name, flags, file size, file name.
759.It Ev LS_SAMESORT
760If this variable is set, the
761.Fl t
762option sorts the names of files with the same modification timestamp in the same
763sense as the time sort.
764See the description of the
765.Fl t
766option for more details.
767.It Ev TERM
768The
769.Ev CLICOLOR
770functionality depends on a terminal type with color capabilities.
771.It Ev TZ
772The timezone to use when displaying dates.
773See
774.Xr environ 7
775for more information.
776.El
777.Sh EXIT STATUS
778.Ex -std
779.Sh EXAMPLES
780List the contents of the current working directory in long format:
781.Pp
782.Dl $ ls -l
783.Pp
784In addition to listing the contents of the current working directory in
785long format, show inode numbers, file flags (see
786.Xr chflags 1 ) ,
787and suffix each filename with a symbol representing its file type:
788.Pp
789.Dl $ ls -lioF
790.Pp
791List the files in
792.Pa /var/log ,
793sorting the output such that the mostly recently modified entries are
794printed first:
795.Pp
796.Dl $ ls -lt /var/log
797.Sh COMPATIBILITY
798The group field is now automatically included in the long listing for
799files in order to be compatible with the
800.St -p1003.2
801specification.
802.Sh SEE ALSO
803.Xr chflags 1 ,
804.Xr chmod 1 ,
805.Xr getfacl 1 ,
806.Xr sort 1 ,
807.Xr xterm 1 ,
808.Xr libxo 3 ,
809.Xr localeconv 3 ,
810.Xr strftime 3 ,
811.Xr strmode 3 ,
812.Xr xo_parse_args 3 ,
813.Xr termcap 5 ,
814.Xr maclabel 7 ,
815.Xr sticky 7 ,
816.Xr symlink 7 ,
817.Xr getfmac 8
818.Sh STANDARDS
819With the exception of options
820.Fl g , n
821and
822.Fl o ,
823the
824.Nm
825utility conforms to
826.St -p1003.1-2001 .
827The options
828.Fl B , D , G , I , T , U , W , Z , b , h , w , y
829and
830.Fl ,
831are compatible extensions not defined in
832.St -p1003.1-2001 .
833.Pp
834The ACL support is compatible with
835.Tn IEEE
836Std\~1003.2c
837.Pq Dq Tn POSIX Ns .2c
838Draft\~17
839(withdrawn).
840.Sh HISTORY
841An
842.Nm
843command appeared in
844.At v1 .
845.Sh BUGS
846To maintain backward compatibility, the relationships between the many
847options are quite complex.
848.Pp
849The exception mentioned in the
850.Fl s
851option description might be a feature that was
852based on the fact that single-column output
853usually goes to something other than a terminal.
854It is debatable whether this is a design bug.
855.Pp
856.St -p1003.2
857mandates opposite sort orders for files with the same timestamp when
858sorting with the
859.Fl t
860option.
861