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