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