]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - bin/ls/ls.1
Add a -I option to disable the automatic -A flag for the super-user.
[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 ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1
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 .Fl I
77 cancel this option.
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 This option cancels the
124 .Fl A
125 option. Usually used by super-user when
126 .Fl A
127 is not necessary.
128 .It Fl L
129 If argument is a symbolic link, list the file or directory the link references
130 rather than the link itself.
131 This option cancels the
132 .Fl P
133 option.
134 .It Fl P
135 If argument is a symbolic link, list the link itself rather than the
136 object the link references.
137 This option cancels the
138 .Fl H
139 and
140 .Fl L
141 options.
142 .It Fl R
143 Recursively list subdirectories encountered.
144 .It Fl S
145 Sort by size (largest file first) before sorting the operands in
146 lexicographical order.
147 .It Fl T
148 When used with the
149 .Fl l
150 (lowercase letter
151 .Dq ell )
152 option, display complete time information for the file, including
153 month, day, hour, minute, second, and year.
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
269 and
270 .Fl u
271 options override each other; the last one specified determines
272 the file time used.
273 .Pp
274 The
275 .Fl B , b , w ,
276 and
277 .Fl q
278 options all override each other; the last one specified determines
279 the format used for non-printable characters.
280 .Pp
281 The
282 .Fl H , L
283 and
284 .Fl P
285 options all override each other (either partially or fully); they
286 are applied in the order specified.
287 .Pp
288 By default,
289 .Nm
290 lists one entry per line to standard
291 output; the exceptions are to terminals or when the
292 .Fl C
293 or
294 .Fl x
295 options are specified.
296 .Pp
297 File information is displayed with one or more
298 .Ao blank Ac Ns s
299 separating the information associated with the
300 .Fl i , s ,
301 and
302 .Fl l
303 options.
304 .Ss The Long Format
305 If the
306 .Fl l
307 option is given, the following information
308 is displayed for each file:
309 file mode,
310 number of links, owner name, group name,
311 MAC label,
312 number of bytes in the file, abbreviated
313 month, day-of-month file was last modified,
314 hour file last modified, minute file last
315 modified, and the pathname.
316 .Pp
317 If the modification time of the file is more than 6 months
318 in the past or future, then the year of the last modification
319 is displayed in place of the hour and minute fields.
320 .Pp
321 If the owner or group names are not a known user or group name,
322 or the
323 .Fl n
324 option is given,
325 the numeric ID's are displayed.
326 .Pp
327 If the file is a character special or block special file,
328 the major and minor device numbers for the file are displayed
329 in the size field.
330 If the file is a symbolic link the pathname of the
331 linked-to file is preceded by
332 .Dq Li -> .
333 .Pp
334 The listing of a directory's contents is preceded
335 by a labeled total number of blocks used in the file system by the files
336 which are listed as the directory's contents
337 (which may or may not include
338 .Pa \&.
339 and
340 .Pa ..
341 and other files which start with a dot, depending on other options).
342 .Pp
343 The default block size is 512 bytes.
344 The block size may be set with option
345 .Fl k
346 or environment variable
347 .Ev BLOCKSIZE .
348 Numbers of blocks in the output will have been rounded up so the
349 numbers of bytes is at least as many as used by the corresponding
350 file system blocks (which might have a different size).
351 .Pp
352 The file mode printed under the
353 .Fl l
354 option consists of the
355 entry type and the permissions.
356 The entry type character describes the type of file, as
357 follows:
358 .Pp
359 .Bl -tag -width 4n -offset indent -compact
360 .It Sy b
361 Block special file.
362 .It Sy c
363 Character special file.
364 .It Sy d
365 Directory.
366 .It Sy l
367 Symbolic link.
368 .It Sy s
369 Socket link.
370 .It Sy p
371 .Tn FIFO .
372 .It Sy \-
373 Regular file.
374 .El
375 .Pp
376 The next three fields
377 are three characters each:
378 owner permissions,
379 group permissions, and
380 other permissions.
381 Each field has three character positions:
382 .Bl -enum -offset indent
383 .It
384 If
385 .Sy r ,
386 the file is readable; if
387 .Sy \- ,
388 it is not readable.
389 .It
390 If
391 .Sy w ,
392 the file is writable; if
393 .Sy \- ,
394 it is not writable.
395 .It
396 The first of the following that applies:
397 .Bl -tag -width 4n -offset indent
398 .It Sy S
399 If in the owner permissions, the file is not executable and
400 set-user-ID mode is set.
401 If in the group permissions, the file is not executable
402 and set-group-ID mode is set.
403 .It Sy s
404 If in the owner permissions, the file is executable
405 and set-user-ID mode is set.
406 If in the group permissions, the file is executable
407 and setgroup-ID mode is set.
408 .It Sy x
409 The file is executable or the directory is
410 searchable.
411 .It Sy \-
412 The file is neither readable, writable, executable,
413 nor set-user-ID nor set-group-ID mode, nor sticky.
414 (See below.)
415 .El
416 .Pp
417 These next two apply only to the third character in the last group
418 (other permissions).
419 .Bl -tag -width 4n -offset indent
420 .It Sy T
421 The sticky bit is set
422 (mode
423 .Li 1000 ) ,
424 but not execute or search permission.
425 (See
426 .Xr chmod 1
427 or
428 .Xr sticky 8 . )
429 .It Sy t
430 The sticky bit is set (mode
431 .Li 1000 ) ,
432 and is searchable or executable.
433 (See
434 .Xr chmod 1
435 or
436 .Xr sticky 8 . )
437 .El
438 .El
439 .Pp
440 The next field contains a
441 plus
442 .Pq Ql +
443 character if the file has an ACL, or a
444 space
445 .Pq Ql " "
446 if it does not.
447 The
448 .Nm
449 utility does not show the actual ACL;
450 use
451 .Xr getfacl 1
452 to do this.
453 .Sh ENVIRONMENT
454 The following environment variables affect the execution of
455 .Nm :
456 .Bl -tag -width ".Ev CLICOLOR_FORCE"
457 .It Ev BLOCKSIZE
458 If this is set, its value, rounded up to 512 or down to a
459 multiple of 512, will be used as the block size in bytes by the
460 .Fl l
461 and
462 .Fl s
463 options.
464 See
465 .Sx The Long Format
466 subsection for more information.
467 .It Ev CLICOLOR
468 Use
469 .Tn ANSI
470 color sequences to distinguish file types.
471 See
472 .Ev LSCOLORS
473 below.
474 In addition to the file types mentioned in the
475 .Fl F
476 option some extra attributes (setuid bit set, etc.) are also displayed.
477 The colorization is dependent on a terminal type with the proper
478 .Xr termcap 5
479 capabilities.
480 The default
481 .Dq Li cons25
482 console has the proper capabilities,
483 but to display the colors in an
484 .Xr xterm 1 ,
485 for example,
486 the
487 .Ev TERM
488 variable must be set to
489 .Dq Li xterm-color .
490 Other terminal types may require similar adjustments.
491 Colorization
492 is silently disabled if the output is not directed to a terminal
493 unless the
494 .Ev CLICOLOR_FORCE
495 variable is defined.
496 .It Ev CLICOLOR_FORCE
497 Color sequences are normally disabled if the output is not directed to
498 a terminal.
499 This can be overridden by setting this flag.
500 The
501 .Ev TERM
502 variable still needs to reference a color capable terminal however
503 otherwise it is not possible to determine which color sequences to
504 use.
505 .It Ev COLUMNS
506 If this variable contains a string representing a
507 decimal integer, it is used as the
508 column position width for displaying
509 multiple-text-column output.
510 The
511 .Nm
512 utility calculates how
513 many pathname text columns to display
514 based on the width provided.
515 (See
516 .Fl C
517 and
518 .Fl x . )
519 .It Ev LANG
520 The locale to use when determining the order of day and month in the long
521 .Fl l
522 format output.
523 See
524 .Xr environ 7
525 for more information.
526 .It Ev LSCOLORS
527 The value of this variable describes what color to use for which
528 attribute when colors are enabled with
529 .Ev CLICOLOR .
530 This string is a concatenation of pairs of the format
531 .Ar f Ns Ar b ,
532 where
533 .Ar f
534 is the foreground color and
535 .Ar b
536 is the background color.
537 .Pp
538 The color designators are as follows:
539 .Pp
540 .Bl -tag -width 4n -offset indent -compact
541 .It Sy a
542 black
543 .It Sy b
544 red
545 .It Sy c
546 green
547 .It Sy d
548 brown
549 .It Sy e
550 blue
551 .It Sy f
552 magenta
553 .It Sy g
554 cyan
555 .It Sy h
556 light grey
557 .It Sy A
558 bold black, usually shows up as dark grey
559 .It Sy B
560 bold red
561 .It Sy C
562 bold green
563 .It Sy D
564 bold brown, usually shows up as yellow
565 .It Sy E
566 bold blue
567 .It Sy F
568 bold magenta
569 .It Sy G
570 bold cyan
571 .It Sy H
572 bold light grey; looks like bright white
573 .It Sy x
574 default foreground or background
575 .El
576 .Pp
577 Note that the above are standard
578 .Tn ANSI
579 colors.
580 The actual display may differ
581 depending on the color capabilities of the terminal in use.
582 .Pp
583 The order of the attributes are as follows:
584 .Pp
585 .Bl -enum -offset indent -compact
586 .It
587 directory
588 .It
589 symbolic link
590 .It
591 socket
592 .It
593 pipe
594 .It
595 executable
596 .It
597 block special
598 .It
599 character special
600 .It
601 executable with setuid bit set
602 .It
603 executable with setgid bit set
604 .It
605 directory writable to others, with sticky bit
606 .It
607 directory writable to others, without sticky bit
608 .El
609 .Pp
610 The default is
611 .Qq "exfxcxdxbxegedabagacad" ,
612 i.e., blue foreground and
613 default background for regular directories, black foreground and red
614 background for setuid executables, etc.
615 .It Ev LS_COLWIDTHS
616 If this variable is set, it is considered to be a
617 colon-delimited list of minimum column widths.
618 Unreasonable
619 and insufficient widths are ignored (thus zero signifies
620 a dynamically sized column).
621 Not all columns have changeable widths.
622 The fields are,
623 in order: inode, block count, number of links, user name,
624 group name, flags, file size, file name.
625 .It Ev TERM
626 The
627 .Ev CLICOLOR
628 functionality depends on a terminal type with color capabilities.
629 .It Ev TZ
630 The timezone to use when displaying dates.
631 See
632 .Xr environ 7
633 for more information.
634 .El
635 .Sh EXIT STATUS
636 .Ex -std
637 .Sh COMPATIBILITY
638 The group field is now automatically included in the long listing for
639 files in order to be compatible with the
640 .St -p1003.2
641 specification.
642 .Sh SEE ALSO
643 .Xr chflags 1 ,
644 .Xr chmod 1 ,
645 .Xr getfacl 1 ,
646 .Xr sort 1 ,
647 .Xr xterm 1 ,
648 .Xr termcap 5 ,
649 .Xr maclabel 7 ,
650 .Xr symlink 7 ,
651 .Xr getfmac 8 ,
652 .Xr sticky 8
653 .Sh STANDARDS
654 With the exception of options
655 .Fl g ,
656 .Fl n
657 and
658 .Fl o ,
659 the
660 .Nm
661 utility conforms to
662 .St -p1003.1-2001 .
663 .Pp
664 The ACL support is compatible with
665 .Tn IEEE
666 Std\~1003.2c
667 .Pq Dq Tn POSIX Ns .2c
668 Draft\~17
669 (withdrawn).
670 .Sh HISTORY
671 An
672 .Nm
673 command appeared in
674 .At v1 .
675 .Sh BUGS
676 To maintain backward compatibility, the relationships between the many
677 options are quite complex.
678 .Pp
679 The exception mentioned in the
680 .Fl s
681 option description might be a feature that was
682 based on the fact that single-column output
683 usually goes to something other than a terminal.
684 It is debatable whether this is a design bug.