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