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