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