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