Synchronise with FreeBSD v1.65:
[dragonfly.git] / bin / ls / ls.1
1 .\" Copyright (c) 1980, 1990, 1991, 1993, 1994
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgment:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)ls.1        8.7 (Berkeley) 7/29/94
36 .\" $FreeBSD: src/bin/ls/ls.1,v 1.33.2.21 2003/05/07 23:56:14 trhodes Exp $
37 .\" $DragonFly: src/bin/ls/ls.1,v 1.4 2005/09/18 11:31:08 asmodai Exp $
38 .\"
39 .Dd July 8, 2002
40 .Dt LS 1
41 .Os
42 .Sh NAME
43 .Nm ls
44 .Nd list directory contents
45 .Sh SYNOPSIS
46 .Nm
47 .Op Fl ABCFGHLPRTWabcdfghiklmnopqrstuwxy1
48 .Op Ar
49 .Sh DESCRIPTION
50 For each operand that names a
51 .Ar file
52 of a type other than
53 directory,
54 .Nm
55 displays its name as well as any requested,
56 associated information.
57 For each operand that names a
58 .Ar file
59 of type directory,
60 .Nm
61 displays the names of files contained
62 within that directory, as well as any requested, associated
63 information.
64 .Pp
65 If no operands are given, the contents of the current
66 directory are displayed.
67 If more than one operand is given,
68 non-directory operands are displayed first; directory
69 and non-directory operands are sorted separately and in
70 lexicographical order.
71 .Pp
72 The following options are available:
73 .Bl -tag -width indent
74 .It Fl A
75 List all entries except for
76 .Pa \&.
77 and
78 .Pa .. .
79 Always set for the super-user.
80 .It Fl B
81 Force printing of non-printable characters (as defined by
82 .Xr ctype 3
83 and current locale settings) in file names as
84 .Li \e Ns Va xxx ,
85 where
86 .Va xxx
87 is the numeric value of the character in octal.
88 .It Fl C
89 Force multi-column output; this is the default when output is to a terminal.
90 .It Fl F
91 Display a slash
92 .Pq Ql /
93 immediately after each pathname that is a directory,
94 an asterisk
95 .Pq Ql *
96 after each that is executable,
97 an at sign
98 .Pq Ql @
99 after each symbolic link,
100 an equals sign
101 .Pq Ql =
102 after each socket,
103 a percent sign
104 .Pq Ql %
105 after each whiteout,
106 and a vertical bar
107 .Pq Ql \&|
108 after each that is a
109 .Tn FIFO .
110 .It Fl G
111 Enable colorized output.
112 This option is equivalent to defining
113 .Ev CLICOLOR
114 in the environment.
115 (See below.)
116 .It Fl H
117 Symbolic links on the command line are followed.
118 This option is assumed if
119 none of the
120 .Fl F , d ,
121 or
122 .Fl l
123 options are specified.
124 .It Fl L
125 If argument is a symbolic link, list the file or directory the link references
126 rather than the link itself.
127 This option cancels the
128 .Fl P
129 option.
130 .It Fl P
131 If argument is a symbolic link, list the link itself rather than the
132 object the link references.
133 This option cancels the
134 .Fl H
135 and
136 .Fl L
137 options.
138 .It Fl R
139 Recursively list subdirectories encountered.
140 .It Fl T
141 When used with the
142 .Fl l
143 (lowercase letter
144 .Dq ell )
145 option, display complete time information for the file, including
146 month, day, hour, minute, second, and year.
147 .It Fl W
148 Display whiteouts when scanning directories.
149 .It Fl a
150 Include directory entries whose names begin with a
151 dot
152 .Pq Pa \&. .
153 .It Fl b
154 As
155 .Fl B ,
156 but use
157 .Tn C
158 escape codes whenever possible.
159 .It Fl c
160 Use time when file status was last changed for sorting or printing.
161 .It Fl d
162 Directories are listed as plain files (not searched recursively).
163 .It Fl f
164 Output is not sorted.
165 .It Fl g
166 This option is deprecated and is only available for compatibility
167 with
168 .Bx 4.3 ;
169 it was used to display the group name in the long
170 .Pq Fl l
171 format output.
172 .It Fl h
173 When used with the
174 .Fl l
175 option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte
176 and Petabyte in order to reduce the number of digits to four or fewer
177 using base 2 for sizes.
178 .It Fl i
179 For each file, print the file's file serial number (inode number).
180 .It Fl k
181 If the
182 .Fl s
183 option is specified, print the file size allocation in kilobytes,
184 not blocks.
185 This option overrides the environment variable
186 .Ev BLOCKSIZE .
187 .It Fl l
188 (The lowercase letter
189 .Dq ell . )
190 List in long format.
191 (See below.)
192 If the output is to a terminal, a total sum for all the file
193 sizes is output on a line before the long listing.
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 to get reverse
216 lexicographical order or the oldest entries first.
217 .It Fl s
218 Display the number of file system blocks actually used by each file, in units
219 of 512 bytes, where partial units are rounded up to the next integer value.
220 If the output is to a terminal, a total sum for all the file
221 sizes is output on a line before the listing.
222 The environment variable
223 .Ev BLOCKSIZE
224 overrides the unit size of 512 bytes.
225 .It Fl t
226 Sort by time modified (most recently modified
227 first) before sorting the operands by lexicographical
228 order.
229 .It Fl u
230 Use time of last access,
231 instead of last modification
232 of the file for sorting
233 .Pq Fl t
234 or printing
235 .Pq Fl l .
236 .It Fl w
237 Force raw printing of non-printable characters.
238 This is the default
239 when output is not to a terminal.
240 .It Fl x
241 The same as
242 .Fl C ,
243 except that the multi-column output is produced with entries sorted
244 across, rather than down, the columns.
245 .It Fl y
246 Include the FSMID field in a long
247 .Pq Fl l
248 output.
249 .It Fl 1
250 (The numeric digit
251 .Dq one . )
252 Force output to be
253 one entry per line.
254 This is the default when
255 output is not to a terminal.
256 .El
257 .Pp
258 The
259 .Fl 1 , C , x ,
260 and
261 .Fl l
262 options all override each other; the last one specified determines
263 the format used.
264 .Pp
265 The
266 .Fl c
267 and
268 .Fl u
269 options override each other; the last one specified determines
270 the file time used.
271 .Pp
272 The
273 .Fl B , b , w ,
274 and
275 .Fl q
276 options all override each other; the last one specified determines
277 the format used for non-printable characters.
278 .Pp
279 The
280 .Fl H , L
281 and
282 .Fl P
283 options all override each other (either partially or fully); they
284 are applied in the order specified.
285 .Pp
286 By default,
287 .Nm
288 lists one entry per line to standard
289 output; the exceptions are to terminals or when the
290 .Fl C
291 or
292 .Fl x
293 options are specified.
294 .Pp
295 File information is displayed with one or more
296 .Ao blank Ac Ns s
297 separating the information associated with the
298 .Fl i , s ,
299 and
300 .Fl l
301 options.
302 .Ss The Long Format
303 If the
304 .Fl l
305 option is given, the following information
306 is displayed for each file:
307 file mode,
308 number of links, owner name, group name,
309 number of bytes in the file, abbreviated
310 month, day-of-month file was last modified,
311 hour file last modified, minute file last
312 modified, and the pathname.
313 In addition, for each directory whose contents are displayed, the total
314 number of 512-byte blocks used by the files in the directory is displayed
315 on a line by itself immediately before the information for the files in the
316 directory.
317 .Pp
318 If the modification time of the file is more than 6 months
319 in the past or future, then the year of the last modification
320 is displayed in place of the hour and minute fields.
321 .Pp
322 If the owner or group names are not a known user or group name,
323 or the
324 .Fl n
325 option is given,
326 the numeric ID's are displayed.
327 .Pp
328 If the file is a character special or block special file,
329 the major and minor device numbers for the file are displayed
330 in the size field.
331 If the file is a symbolic link the pathname of the
332 linked-to file is preceded by
333 .Dq Li -> .
334 .Pp
335 The file mode printed under the
336 .Fl l
337 option consists of the
338 entry type, owner permissions, and group permissions.
339 The entry type character describes the type of file, as
340 follows:
341 .Pp
342 .Bl -tag -width 4n -offset indent -compact
343 .It Sy b
344 Block special file.
345 .It Sy c
346 Character special file.
347 .It Sy d
348 Directory.
349 .It Sy l
350 Symbolic link.
351 .It Sy s
352 Socket link.
353 .It Sy p
354 .Tn FIFO .
355 .It Sy \-
356 Regular file.
357 .El
358 .Pp
359 The next three fields
360 are three characters each:
361 owner permissions,
362 group permissions, and
363 other permissions.
364 Each field has three character positions:
365 .Bl -enum -offset indent
366 .It
367 If
368 .Sy r ,
369 the file is readable; if
370 .Sy \- ,
371 it is not readable.
372 .It
373 If
374 .Sy w ,
375 the file is writable; if
376 .Sy \- ,
377 it is not writable.
378 .It
379 The first of the following that applies:
380 .Bl -tag -width 4n -offset indent
381 .It Sy S
382 If in the owner permissions, the file is not executable and
383 set-user-ID mode is set.
384 If in the group permissions, the file is not executable
385 and set-group-ID mode is set.
386 .It Sy s
387 If in the owner permissions, the file is executable
388 and set-user-ID mode is set.
389 If in the group permissions, the file is executable
390 and setgroup-ID mode is set.
391 .It Sy x
392 The file is executable or the directory is
393 searchable.
394 .It Sy \-
395 The file is neither readable, writable, executable,
396 nor set-user-ID nor set-group-ID mode, nor sticky.
397 (See below.)
398 .El
399 .Pp
400 These next two apply only to the third character in the last group
401 (other permissions).
402 .Bl -tag -width 4n -offset indent
403 .It Sy T
404 The sticky bit is set
405 (mode
406 .Li 1000 ) ,
407 but not execute or search permission.
408 (See
409 .Xr chmod 1
410 or
411 .Xr sticky 8 . )
412 .It Sy t
413 The sticky bit is set (mode
414 .Li 1000 ) ,
415 and is searchable or executable.
416 (See
417 .Xr chmod 1
418 or
419 .Xr sticky 8 . )
420 .El
421 .El
422 .Sh EXAMPLES
423 The following is how to do an
424 .Nm
425 listing sorted by size (and shows why
426 .Nm
427 does not need a separate option for this):
428 .Pp
429 .Dl "ls -l | sort -n +4"
430 .Pp
431 Additionally, the
432 .Fl r
433 flag to
434 .Xr sort 1
435 may be used
436 to get the results sorted from largest to smallest (a reverse sort).
437 .Sh DIAGNOSTICS
438 .Ex -std
439 .Sh ENVIRONMENT
440 The following environment variables affect the execution of
441 .Nm :
442 .Bl -tag -width ".Ev CLICOLOR_FORCE"
443 .It Ev BLOCKSIZE
444 If the environment variable
445 .Ev BLOCKSIZE
446 is set, the block counts
447 (see
448 .Fl s )
449 will be displayed in units of that size block.
450 .It Ev CLICOLOR
451 Use
452 .Tn ANSI
453 color sequences to distinguish file types.
454 See
455 .Ev LSCOLORS
456 below.
457 In addition to the file types mentioned in the
458 .Fl F
459 option some extra attributes (setuid bit set, etc.) are also displayed.
460 The colorization is dependent on a terminal type with the proper
461 .Xr termcap 5
462 capabilities.
463 The default
464 .Dq Li cons25
465 console has the proper capabilities,
466 but to display the colors in an
467 .Xr xterm 1 ,
468 for example,
469 the
470 .Ev TERM
471 variable must be set to
472 .Dq Li xterm-color .
473 Other terminal types may require similar adjustments.
474 Colorization
475 is silently disabled if the output isn't directed to a terminal
476 unless the
477 .Ev CLICOLOR_FORCE
478 variable is defined.
479 .It Ev CLICOLOR_FORCE
480 Color sequences are normally disabled if the output isn't directed to
481 a terminal.
482 This can be overridden by setting this flag.
483 The
484 .Ev TERM
485 variable still needs to reference a color capable terminal however
486 otherwise it is not possible to determine which color sequences to
487 use.
488 .It Ev COLUMNS
489 If this variable contains a string representing a
490 decimal integer, it is used as the
491 column position width for displaying
492 multiple-text-column output.
493 The
494 .Nm
495 utility calculates how
496 many pathname text columns to display
497 based on the width provided.
498 (See
499 .Fl C
500 and
501 .Fl x . )
502 .It Ev LANG
503 The locale to use when determining the order of day and month in the long
504 .Fl l
505 format output.
506 See
507 .Xr environ 7
508 for more information.
509 .It Ev LSCOLORS
510 The value of this variable describes what color to use for which
511 attribute when colors are enabled with
512 .Ev CLICOLOR .
513 This string is a concatenation of pairs of the format
514 .Ar f Ns Ar b ,
515 where
516 .Ar f
517 is the foreground color and
518 .Ar b
519 is the background color.
520 .Pp
521 The color designators are as follows:
522 .Pp
523 .Bl -tag -width 4n -offset indent -compact
524 .It Sy a
525 black
526 .It Sy b
527 red
528 .It Sy c
529 green
530 .It Sy d
531 brown
532 .It Sy e
533 blue
534 .It Sy f
535 magenta
536 .It Sy g
537 cyan
538 .It Sy h
539 light grey
540 .It Sy A
541 bold black, usually shows up as dark grey
542 .It Sy B
543 bold red
544 .It Sy C
545 bold green
546 .It Sy D
547 bold brown, usually shows up as yellow
548 .It Sy E
549 bold blue
550 .It Sy F
551 bold magenta
552 .It Sy G
553 bold cyan
554 .It Sy H
555 bold light grey; looks like bright white
556 .It Sy x
557 default foreground or background
558 .El
559 .Pp
560 Note that the above are standard
561 .Tn ANSI
562 colors.
563 The actual display may differ
564 depending on the color capabilities of the terminal in use.
565 .Pp
566 The order of the attributes are as follows:
567 .Pp
568 .Bl -enum -offset indent -compact
569 .It
570 directory
571 .It
572 symbolic link
573 .It
574 socket
575 .It
576 pipe
577 .It
578 executable
579 .It
580 block special
581 .It
582 character special
583 .It
584 executable with setuid bit set
585 .It
586 executable with setgid bit set
587 .It
588 directory writable to others, with sticky bit
589 .It
590 directory writable to others, without sticky bit
591 .El
592 .Pp
593 The default is
594 .Qq "exfxcxdxbxegedabagacad" ,
595 i.e. blue foreground and
596 default background for regular directories, black foreground and red
597 background for setuid executables, etc.
598 .It Ev LS_COLWIDTHS
599 If this variable is set, it is considered to be a
600 colon-delimited list of minimum column widths.
601 Unreasonable
602 and insufficient widths are ignored (thus zero signifies
603 a dynamically sized column).
604 Not all columns have changeable widths.
605 The fields are,
606 in order: inode, block count, number of links, user name,
607 group name, flags, file size, file name.
608 .It Ev TERM
609 The
610 .Ev CLICOLOR
611 functionality depends on a terminal type with color capabilities.
612 .It Ev TZ
613 The timezone to use when displaying dates.
614 See
615 .Xr environ 7
616 for more information.
617 .El
618 .Sh COMPATIBILITY
619 The group field is now automatically included in the long listing for
620 files in order to be compatible with the
621 .St -p1003.2
622 specification.
623 .Sh SEE ALSO
624 .Xr chflags 1 ,
625 .Xr chmod 1 ,
626 .Xr sort 1 ,
627 .Xr xterm 1 ,
628 .Xr termcap 5 ,
629 .Xr symlink 7 ,
630 .Xr sticky 8
631 .Sh STANDARDS
632 The
633 .Nm
634 utility conforms to
635 .St -p1003.1-2001 .
636 .Sh HISTORY
637 An
638 .Nm
639 command appeared in
640 .At v1 .
641 .Sh BUGS
642 To maintain backward compatibility, the relationships between the many
643 options are quite complex.