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