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