xref: /freebsd/bin/ls/ls.1 (revision 78b9f0095b4af3aca6c931b2c7b009ddb8a05125)
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.\" 3. 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 August 8, 2018
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 ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,
44.Op Fl D Ar format
45.Op Ar
46.Sh DESCRIPTION
47For each operand that names a
48.Ar file
49of a type other than
50directory,
51.Nm
52displays its name as well as any requested,
53associated information.
54For each operand that names a
55.Ar file
56of type directory,
57.Nm
58displays the names of files contained
59within that directory, as well as any requested, associated
60information.
61.Pp
62If no operands are given, the contents of the current
63directory are displayed.
64If more than one operand is given,
65non-directory operands are displayed first; directory
66and non-directory operands are sorted separately and in
67lexicographical order.
68.Pp
69The following options are available:
70.Bl -tag -width indent
71.It Fl A
72Include directory entries whose names begin with a
73dot
74.Pq Sq Pa \&.
75except for
76.Pa \&.
77and
78.Pa .. .
79Automatically set for the super-user unless
80.Fl I
81is specified.
82.It Fl B
83Force printing of non-printable characters (as defined by
84.Xr ctype 3
85and current locale settings) in file names as
86.Li \e Ns Va xxx ,
87where
88.Va xxx
89is the numeric value of the character in octal.
90This option is not defined in
91.St -p1003.1-2001 .
92.It Fl C
93Force multi-column output; this is the default when output is to a terminal.
94.It Fl D Ar format
95When printing in the long
96.Pq Fl l
97format, use
98.Ar format
99to format the date and time output.
100The argument
101.Ar format
102is a string used by
103.Xr strftime 3 .
104Depending on the choice of format string, this may result in a
105different number of columns in the output.
106This option overrides the
107.Fl T
108option.
109This option is not defined in
110.St -p1003.1-2001 .
111.It Fl F
112Display a slash
113.Pq Ql /
114immediately after each pathname that is a directory,
115an asterisk
116.Pq Ql *
117after each that is executable,
118an at sign
119.Pq Ql @
120after each symbolic link,
121an equals sign
122.Pq Ql =
123after each socket,
124a percent sign
125.Pq Ql %
126after each whiteout,
127and a vertical bar
128.Pq Ql \&|
129after each that is a
130.Tn FIFO .
131.It Fl G
132Enable colorized output.
133This option is equivalent to defining
134.Ev CLICOLOR
135or
136.Ev COLORTERM
137in the environment.
138(See below.)
139This functionality can be compiled out by removing the definition of
140.Ev COLORLS .
141This option is not defined in
142.St -p1003.1-2001 .
143.It Fl H
144Symbolic links on the command line are followed.
145This option is assumed if
146none of the
147.Fl F , d ,
148or
149.Fl l
150options are specified.
151.It Fl I
152Prevent
153.Fl A
154from being automatically set for the super-user.
155This option is not defined in
156.St -p1003.1-2001 .
157.It Fl L
158If argument is a symbolic link, list the file or directory the link references
159rather than the link itself.
160This option cancels the
161.Fl P
162option.
163.It Fl P
164If argument is a symbolic link, list the link itself rather than the
165object the link references.
166This option cancels the
167.Fl H
168and
169.Fl L
170options.
171.It Fl R
172Recursively list subdirectories encountered.
173.It Fl S
174Sort by size (largest file first) before sorting the operands in
175lexicographical order.
176.It Fl T
177When printing in the long
178.Pq Fl l
179format, display complete time information for the file, including
180month, day, hour, minute, second, and year.
181The
182.Fl D
183option gives even more control over the output format.
184This option is not defined in
185.St -p1003.1-2001 .
186.It Fl U
187Use time when file was created for sorting or printing.
188This option is not defined in
189.St -p1003.1-2001 .
190.It Fl W
191Display whiteouts when scanning directories.
192This option is not defined in
193.St -p1003.1-2001 .
194.It Fl Z
195Display each file's MAC label; see
196.Xr maclabel 7 .
197This option is not defined in
198.St -p1003.1-2001 .
199.It Fl a
200Include directory entries whose names begin with a
201dot
202.Pq Sq Pa \&. .
203.It Fl b
204As
205.Fl B ,
206but use
207.Tn C
208escape codes whenever possible.
209This option is not defined in
210.St -p1003.1-2001 .
211.It Fl c
212Use time when file status was last changed for sorting or printing.
213.It Fl d
214Directories are listed as plain files (not searched recursively).
215.It Fl f
216Output is not sorted.
217This option turns on
218.Fl a .
219It also negates the effect of the
220.Fl r ,
221.Fl S
222and
223.Fl t
224options.
225As allowed by
226.St -p1003.1-2001 ,
227this option has no effect on the
228.Fl d ,
229.Fl l ,
230.Fl R
231and
232.Fl s
233options.
234.It Fl g
235This option has no effect.
236It is only available for compatibility with
237.Bx 4.3 ,
238where it was used to display the group name in the long
239.Pq Fl l
240format output.
241This option is incompatible with
242.St -p1003.1-2001 .
243.It Fl h
244When used with the
245.Fl l
246option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte
247and Petabyte in order to reduce the number of digits to four or fewer
248using base 2 for sizes.
249This option is not defined in
250.St -p1003.1-2001 .
251.It Fl i
252For each file, print the file's file serial number (inode number).
253.It Fl k
254This has the same effect as setting environment variable
255.Ev BLOCKSIZE
256to 1024, except that it also nullifies any
257.Fl h
258options to its left.
259.It Fl l
260(The lowercase letter
261.Dq ell . )
262List files in the long format, as described in the
263.Sx The Long Format
264subsection below.
265.It Fl m
266Stream output format; list files across the page, separated by commas.
267.It Fl n
268Display user and group IDs numerically rather than converting to a user
269or group name in a long
270.Pq Fl l
271output.
272.It Fl o
273Include the file flags in a long
274.Pq Fl l
275output.
276This option is incompatible with
277.St -p1003.1-2001 .
278See
279.Xr chflags 1
280for a list of file flags and their meanings.
281.It Fl p
282Write a slash
283.Pq Ql /
284after each filename if that file is a directory.
285.It Fl q
286Force printing of non-graphic characters in file names as
287the character
288.Ql \&? ;
289this is the default when output is to a terminal.
290.It Fl r
291Reverse the order of the sort.
292.It Fl s
293Display the number of blocks used in the file system by each file.
294Block sizes and directory totals are handled as described in
295.Sx The Long Format
296subsection below, except (if the long format is not also requested)
297the directory totals are not output when the output is in a
298single column, even if multi-column output is requested.
299.It Fl t
300Sort by descending time modified (most recently modified first).
301If two files have the same modification timestamp, sort their names
302in ascending lexicographical order.
303The
304.Fl r
305option reverses both of these sort orders.
306.Pp
307Note that these sort orders are contradictory: the time sequence is in
308descending order, the lexicographical sort is in ascending order.
309This behavior is mandated by
310.St -p1003.2 .
311This feature can cause problems listing files stored with sequential names on
312FAT file systems, such as from digital cameras, where it is possible to have
313more than one image with the same timestamp.
314In such a case, the photos cannot be listed in the sequence in which
315they were taken.
316To ensure the same sort order for time and for lexicographical sorting, set the
317environment variable
318.Ev LS_SAMESORT
319or use the
320.Fl y
321option.
322This causes
323.Nm
324to reverse the lexicographical sort order when sorting files with the
325same modification timestamp.
326.It Fl u
327Use time of last access,
328instead of time of last modification
329of the file for sorting
330.Pq Fl t
331or printing
332.Pq Fl l .
333.It Fl w
334Force raw printing of non-printable characters.
335This is the default
336when output is not to a terminal.
337This option is not defined in
338.St -p1003.1-2001 .
339.It Fl x
340The same as
341.Fl C ,
342except that the multi-column output is produced with entries sorted
343across, rather than down, the columns.
344.It Fl y
345When the
346.Fl t
347option is set, sort the alphabetical output in the same order as the time output.
348This has the same effect as setting
349.Ev LS_SAMESORT .
350See the description of the
351.Fl t
352option for more details.
353This option is not defined in
354.St -p1003.1-2001 .
355.It Fl 1
356(The numeric digit
357.Dq one . )
358Force output to be
359one entry per line.
360This is the default when
361output is not to a terminal.
362.It Fl ,
363(Comma) When the
364.Fl l
365option is set, print file sizes grouped and separated by thousands using the
366non-monetary separator returned by
367.Xr localeconv 3 ,
368typically a comma or period.
369If no locale is set, or the locale does not have a non-monetary separator, this
370option has no effect.
371This option is not defined in
372.St -p1003.1-2001 .
373.El
374.Pp
375The
376.Fl 1 , C , x ,
377and
378.Fl l
379options all override each other; the last one specified determines
380the format used.
381.Pp
382The
383.Fl c , u ,
384and
385.Fl U
386options all override each other; the last one specified determines
387the file time used.
388.Pp
389The
390.Fl S
391and
392.Fl t
393options override each other; the last one specified determines
394the sort order used.
395.Pp
396The
397.Fl B , b , w ,
398and
399.Fl q
400options all override each other; the last one specified determines
401the format used for non-printable characters.
402.Pp
403The
404.Fl H , L
405and
406.Fl P
407options all override each other (either partially or fully); they
408are applied in the order specified.
409.Pp
410By default,
411.Nm
412lists one entry per line to standard
413output; the exceptions are to terminals or when the
414.Fl C
415or
416.Fl x
417options are specified.
418.Pp
419File information is displayed with one or more
420.Ao blank Ac Ns s
421separating the information associated with the
422.Fl i , s ,
423and
424.Fl l
425options.
426.Ss The Long Format
427If the
428.Fl l
429option is given, the following information
430is displayed for each file:
431file mode,
432number of links, owner name, group name,
433MAC label,
434number of bytes in the file, abbreviated
435month, day-of-month file was last modified,
436hour file last modified, minute file last
437modified, and the pathname.
438.Pp
439If the modification time of the file is more than 6 months
440in the past or future, and the
441.Fl D
442or
443.Fl T
444are not specified,
445then the year of the last modification
446is displayed in place of the hour and minute fields.
447.Pp
448If the owner or group names are not a known user or group name,
449or the
450.Fl n
451option is given,
452the numeric ID's are displayed.
453.Pp
454If the file is a character special or block special file,
455the device number for the file is displayed in the size field.
456If the file is a symbolic link the pathname of the
457linked-to file is preceded by
458.Dq Li -> .
459.Pp
460The listing of a directory's contents is preceded
461by a labeled total number of blocks used in the file system by the files
462which are listed as the directory's contents
463(which may or may not include
464.Pa \&.
465and
466.Pa ..
467and other files which start with a dot, depending on other options).
468.Pp
469The default block size is 512 bytes.
470The block size may be set with option
471.Fl k
472or environment variable
473.Ev BLOCKSIZE .
474Numbers of blocks in the output will have been rounded up so the
475numbers of bytes is at least as many as used by the corresponding
476file system blocks (which might have a different size).
477.Pp
478The file mode printed under the
479.Fl l
480option consists of the
481entry type and the permissions.
482The entry type character describes the type of file, as
483follows:
484.Pp
485.Bl -tag -width 4n -offset indent -compact
486.It Sy \-
487Regular file.
488.It Sy b
489Block special file.
490.It Sy c
491Character special file.
492.It Sy d
493Directory.
494.It Sy l
495Symbolic link.
496.It Sy p
497.Tn FIFO .
498.It Sy s
499Socket.
500.It Sy w
501Whiteout.
502.El
503.Pp
504The next three fields
505are three characters each:
506owner permissions,
507group permissions, and
508other permissions.
509Each field has three character positions:
510.Bl -enum -offset indent
511.It
512If
513.Sy r ,
514the file is readable; if
515.Sy \- ,
516it is not readable.
517.It
518If
519.Sy w ,
520the file is writable; if
521.Sy \- ,
522it is not writable.
523.It
524The first of the following that applies:
525.Bl -tag -width 4n -offset indent
526.It Sy S
527If in the owner permissions, the file is not executable and
528set-user-ID mode is set.
529If in the group permissions, the file is not executable
530and set-group-ID mode is set.
531.It Sy s
532If in the owner permissions, the file is executable
533and set-user-ID mode is set.
534If in the group permissions, the file is executable
535and setgroup-ID mode is set.
536.It Sy x
537The file is executable or the directory is
538searchable.
539.It Sy \-
540The file is neither readable, writable, executable,
541nor set-user-ID nor set-group-ID mode, nor sticky.
542(See below.)
543.El
544.Pp
545These next two apply only to the third character in the last group
546(other permissions).
547.Bl -tag -width 4n -offset indent
548.It Sy T
549The sticky bit is set
550(mode
551.Li 1000 ) ,
552but not execute or search permission.
553(See
554.Xr chmod 1
555or
556.Xr sticky 7 . )
557.It Sy t
558The sticky bit is set (mode
559.Li 1000 ) ,
560and is searchable or executable.
561(See
562.Xr chmod 1
563or
564.Xr sticky 7 . )
565.El
566.El
567.Pp
568The next field contains a
569plus
570.Pq Ql +
571character if the file has an ACL, or a
572space
573.Pq Ql " "
574if it does not.
575The
576.Nm
577utility does not show the actual ACL;
578use
579.Xr getfacl 1
580to do this.
581.Sh ENVIRONMENT
582The following environment variables affect the execution of
583.Nm :
584.Bl -tag -width ".Ev CLICOLOR_FORCE"
585.It Ev BLOCKSIZE
586If this is set, its value, rounded up to 512 or down to a
587multiple of 512, will be used as the block size in bytes by the
588.Fl l
589and
590.Fl s
591options.
592See
593.Sx The Long Format
594subsection for more information.
595.It Ev CLICOLOR
596Use
597.Tn ANSI
598color sequences to distinguish file types.
599See
600.Ev LSCOLORS
601below.
602In addition to the file types mentioned in the
603.Fl F
604option some extra attributes (setuid bit set, etc.) are also displayed.
605The colorization is dependent on a terminal type with the proper
606.Xr termcap 5
607capabilities.
608The default
609.Dq Li cons25
610console has the proper capabilities,
611but to display the colors in an
612.Xr xterm 1 ,
613for example,
614the
615.Ev TERM
616variable must be set to
617.Dq Li xterm-color .
618Other terminal types may require similar adjustments.
619Colorization
620is silently disabled if the output is not directed to a terminal
621unless the
622.Ev CLICOLOR_FORCE
623variable is defined.
624.It Ev CLICOLOR_FORCE
625Color sequences are normally disabled if the output is not directed to
626a terminal.
627This can be overridden by setting this variable.
628The
629.Ev TERM
630variable still needs to reference a color capable terminal however
631otherwise it is not possible to determine which color sequences to
632use.
633.It Ev COLORTERM
634See description for
635.Ev CLICOLOR
636above.
637.It Ev COLUMNS
638If this variable contains a string representing a
639decimal integer, it is used as the
640column position width for displaying
641multiple-text-column output.
642The
643.Nm
644utility calculates how
645many pathname text columns to display
646based on the width provided.
647(See
648.Fl C
649and
650.Fl x . )
651.It Ev LANG
652The locale to use when determining the order of day and month in the long
653.Fl l
654format output.
655See
656.Xr environ 7
657for more information.
658.It Ev LSCOLORS
659The value of this variable describes what color to use for which
660attribute when colors are enabled with
661.Ev CLICOLOR
662or
663.Ev COLORTERM .
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
770and
771.Ev COLORTERM
772functionality depends on a terminal type with color capabilities.
773.It Ev TZ
774The timezone to use when displaying dates.
775See
776.Xr environ 7
777for more information.
778.El
779.Sh EXIT STATUS
780.Ex -std
781.Sh EXAMPLES
782List the contents of the current working directory in long format:
783.Pp
784.Dl $ ls -l
785.Pp
786In addition to listing the contents of the current working directory in
787long format, show inode numbers, file flags (see
788.Xr chflags 1 ) ,
789and suffix each filename with a symbol representing its file type:
790.Pp
791.Dl $ ls -lioF
792.Pp
793List the files in
794.Pa /var/log ,
795sorting the output such that the mostly recently modified entries are
796printed first:
797.Pp
798.Dl $ ls -lt /var/log
799.Sh COMPATIBILITY
800The group field is now automatically included in the long listing for
801files in order to be compatible with the
802.St -p1003.2
803specification.
804.Sh SEE ALSO
805.Xr chflags 1 ,
806.Xr chmod 1 ,
807.Xr getfacl 1 ,
808.Xr sort 1 ,
809.Xr xterm 1 ,
810.Xr localeconv 3 ,
811.Xr strftime 3 ,
812.Xr strmode 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