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