06250991fdee26ea0108e792c520fbca8988abc7
[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 November 20, 2015
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 using the ISO 8601 extended
154 format.
155 .It Fl W
156 Display whiteouts when scanning directories.
157 .It Fl a
158 Include directory entries whose names begin with a
159 dot
160 .Pq Pa \&. .
161 .It Fl b
162 As
163 .Fl B ,
164 but use
165 .Tn C
166 escape codes whenever possible.
167 .It Fl c
168 Use time when file status was last changed for sorting or printing.
169 .It Fl d
170 Directories are listed as plain files (not searched recursively).
171 .It Fl f
172 Output is not sorted.
173 This option implies
174 .Fl a .
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 If the
192 .Fl s
193 option is specified, print the file size allocation in kilobytes,
194 not blocks.
195 This option overrides the environment variable
196 .Ev BLOCKSIZE .
197 Note that
198 .Fl k
199 is mutually exclusive to
200 .Fl h ,
201 and later
202 .Fl k
203 will nullify earlier
204 .Fl h .
205 .It Fl l
206 (The lowercase letter
207 .Dq ell . )
208 List in long format.
209 (See below.)
210 A total sum (in blocks, see the
211 .Fl s
212 option for the block size unit) for all the file
213 sizes is output on a line before the long listing.
214 .It Fl m
215 Stream output format; list files across the page, separated by commas.
216 .It Fl n
217 Display user and group IDs numerically rather than converting to a user
218 or group name in a long
219 .Pq Fl l
220 output.
221 .It Fl o
222 Include the file flags in a long
223 .Pq Fl l
224 output.
225 .It Fl p
226 Write a slash
227 .Pq Ql /
228 after each filename if that file is a directory.
229 .It Fl q
230 Force printing of non-graphic characters in file names as
231 the character
232 .Ql \&? ;
233 this is the default when output is to a terminal.
234 .It Fl r
235 Reverse the order of the sort to get reverse
236 lexicographical order or the oldest entries first.
237 .It Fl s
238 Display the number of file system blocks actually used by each file, in units
239 of 512 bytes, where partial units are rounded up to the next integer value.
240 A total sum for all the file
241 sizes is output on a line before the listing.
242 The environment variable
243 .Ev BLOCKSIZE
244 overrides the unit size of 512 bytes.
245 .It Fl t
246 Sort by time modified (most recently modified
247 first) before sorting the operands by lexicographical
248 order.
249 .It Fl u
250 Use time of last access,
251 instead of last modification
252 of the file for sorting
253 .Pq Fl t
254 or printing
255 .Pq Fl l .
256 .It Fl w
257 Force raw printing of non-printable characters.
258 This is the default
259 when output is not to a terminal.
260 .It Fl x
261 The same as
262 .Fl C ,
263 except that the multi-column output is produced with entries sorted
264 across, rather than down, the columns.
265 .It Fl y
266 Include the FSMID field in a long
267 .Pq Fl l
268 output.
269 .It Fl 1
270 (The numeric digit
271 .Dq one . )
272 Force output to be
273 one entry per line.
274 This is the default when
275 output is not to a terminal.
276 .El
277 .Pp
278 The
279 .Fl 1 , C , x ,
280 and
281 .Fl l
282 options all override each other; the last one specified determines
283 the format used.
284 .Pp
285 The
286 .Fl c
287 and
288 .Fl u
289 options override each other; the last one specified determines
290 the file time used.
291 .Pp
292 The
293 .Fl B , b , w ,
294 and
295 .Fl q
296 options all override each other; the last one specified determines
297 the format used for non-printable characters.
298 .Pp
299 The
300 .Fl H , L
301 and
302 .Fl P
303 options all override each other (either partially or fully); they
304 are applied in the order specified.
305 .Pp
306 By default,
307 .Nm
308 lists one entry per line to standard
309 output; the exceptions are to terminals or when the
310 .Fl C
311 or
312 .Fl x
313 options are specified.
314 .Pp
315 File information is displayed with one or more
316 .Ao blank Ac Ns s
317 separating the information associated with the
318 .Fl i , s ,
319 and
320 .Fl l
321 options.
322 .Ss The Long Format
323 If the
324 .Fl l
325 option is given, the following information
326 is displayed for each file:
327 file mode,
328 number of links, owner name, group name,
329 number of bytes in the file,
330 last modified time in ISO 8601 basic format reduced to
331 hour accuracy, 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 owner or group names are not a known user or group name,
338 or the
339 .Fl n
340 option is given,
341 the numeric ID's are displayed.
342 .Pp
343 If the file is a character special or block special file,
344 the major and minor device numbers for the file are displayed
345 in the size field.
346 If the file is a symbolic link the pathname of the
347 linked-to file is preceded by
348 .Dq Li -> .
349 .Pp
350 The file mode printed under the
351 .Fl l
352 option consists of the
353 entry type and the permissions.
354 The entry type character describes the type of file, as
355 follows:
356 .Pp
357 .Bl -tag -width 4n -offset indent -compact
358 .It Sy b
359 Block special file.
360 .It Sy c
361 Character special file.
362 .It Sy d
363 Directory.
364 .It Sy l
365 Symbolic link.
366 .It Sy s
367 Socket link.
368 .It Sy p
369 .Tn FIFO .
370 .It Sy \-
371 Regular file.
372 .El
373 .Pp
374 The next three fields
375 are three characters each:
376 owner permissions,
377 group permissions, and
378 other permissions.
379 Each field has three character positions:
380 .Bl -enum -offset indent
381 .It
382 If
383 .Sy r ,
384 the file is readable; if
385 .Sy \- ,
386 it is not readable.
387 .It
388 If
389 .Sy w ,
390 the file is writable; if
391 .Sy \- ,
392 it is not writable.
393 .It
394 The first of the following that applies:
395 .Bl -tag -width 4n -offset indent
396 .It Sy S
397 If in the owner permissions, the file is not executable and
398 set-user-ID mode is set.
399 If in the group permissions, the file is not executable
400 and set-group-ID mode is set.
401 .It Sy s
402 If in the owner permissions, the file is executable
403 and set-user-ID mode is set.
404 If in the group permissions, the file is executable
405 and setgroup-ID mode is set.
406 .It Sy x
407 The file is executable or the directory is
408 searchable.
409 .It Sy \-
410 The file is neither readable, writable, executable,
411 nor set-user-ID nor set-group-ID mode, nor sticky.
412 (See below.)
413 .El
414 .Pp
415 These next two apply only to the third character in the last group
416 (other permissions).
417 .Bl -tag -width 4n -offset indent
418 .It Sy T
419 The sticky bit is set
420 (mode
421 .Li 1000 ) ,
422 but not execute or search permission.
423 (See
424 .Xr chmod 1
425 or
426 .Xr sticky 8 . )
427 .It Sy t
428 The sticky bit is set (mode
429 .Li 1000 ) ,
430 and is searchable or executable.
431 (See
432 .Xr chmod 1
433 or
434 .Xr sticky 8 . )
435 .El
436 .El
437 .Sh ENVIRONMENT
438 The following environment variables affect the execution of
439 .Nm :
440 .Bl -tag -width ".Ev CLICOLOR_FORCE"
441 .It Ev BLOCKSIZE
442 If the environment variable
443 .Ev BLOCKSIZE
444 is set, the block counts
445 (see
446 .Fl s )
447 will be displayed in units of that size block.
448 .It Ev CLICOLOR
449 Use
450 .Tn ANSI
451 color sequences to distinguish file types.
452 See
453 .Ev LSCOLORS
454 below.
455 In addition to the file types mentioned in the
456 .Fl F
457 option some extra attributes (setuid bit set, etc.) are also displayed.
458 The colorization is dependent on a terminal type with the proper
459 .Xr termcap 5
460 capabilities.
461 The default
462 .Dq Li cons25
463 console has the proper capabilities,
464 but to display the colors in an
465 .Xr xterm 1 ,
466 for example,
467 the
468 .Ev TERM
469 variable must be set to
470 .Dq Li xterm-color .
471 Other terminal types may require similar adjustments.
472 Colorization
473 is silently disabled if the output is not directed to a terminal
474 unless the
475 .Ev CLICOLOR_FORCE
476 variable is defined.
477 .It Ev CLICOLOR_FORCE
478 Color sequences are normally disabled if the output is not directed to
479 a terminal.
480 This can be overridden by setting this flag.
481 The
482 .Ev TERM
483 variable still needs to reference a color capable terminal however
484 otherwise it is not possible to determine which color sequences to
485 use.
486 .It Ev COLUMNS
487 If this variable contains a string representing a
488 decimal integer, it is used as the
489 column position width for displaying
490 multiple-text-column output.
491 The
492 .Nm
493 utility calculates how
494 many pathname text columns to display
495 based on the width provided.
496 (See
497 .Fl C
498 and
499 .Fl x . )
500 .It Ev LANG
501 The locale to use when determining the order of day and month in the long
502 .Fl l
503 format output.
504 See
505 .Xr environ 7
506 for more information.
507 .It Ev LSCOLORS
508 The value of this variable describes what color to use for which
509 attribute when colors are enabled with
510 .Ev CLICOLOR .
511 This string is a concatenation of pairs of the format
512 .Ar f Ns Ar b ,
513 where
514 .Ar f
515 is the foreground color and
516 .Ar b
517 is the background color.
518 .Pp
519 The color designators are as follows:
520 .Pp
521 .Bl -tag -width 4n -offset indent -compact
522 .It Sy a
523 black
524 .It Sy b
525 red
526 .It Sy c
527 green
528 .It Sy d
529 brown
530 .It Sy e
531 blue
532 .It Sy f
533 magenta
534 .It Sy g
535 cyan
536 .It Sy h
537 light grey
538 .It Sy A
539 bold black, usually shows up as dark grey
540 .It Sy B
541 bold red
542 .It Sy C
543 bold green
544 .It Sy D
545 bold brown, usually shows up as yellow
546 .It Sy E
547 bold blue
548 .It Sy F
549 bold magenta
550 .It Sy G
551 bold cyan
552 .It Sy H
553 bold light grey; looks like bright white
554 .It Sy x
555 default foreground or background
556 .El
557 .Pp
558 Note that the above are standard
559 .Tn ANSI
560 colors.
561 The actual display may differ
562 depending on the color capabilities of the terminal in use.
563 .Pp
564 The order of the attributes are as follows:
565 .Pp
566 .Bl -enum -offset indent -compact
567 .It
568 directory
569 .It
570 symbolic link
571 .It
572 socket
573 .It
574 pipe
575 .It
576 executable
577 .It
578 block special
579 .It
580 character special
581 .It
582 executable with setuid bit set
583 .It
584 executable with setgid bit set
585 .It
586 directory writable to others, with sticky bit
587 .It
588 directory writable to others, without sticky bit
589 .El
590 .Pp
591 The default is
592 .Qq "exfxcxdxbxegedabagacad" ,
593 i.e., blue foreground and
594 default background for regular directories, black foreground and red
595 background for setuid executables, etc.
596 .It Ev LS_COLWIDTHS
597 If this variable is set, it is considered to be a
598 colon-delimited list of minimum column widths.
599 Unreasonable
600 and insufficient widths are ignored (thus zero signifies
601 a dynamically sized column).
602 Not all columns have changeable widths.
603 The fields are,
604 in order: inode, block count, number of links, user name,
605 group name, flags, file size, file name.
606 .It Ev TERM
607 The
608 .Ev CLICOLOR
609 functionality depends on a terminal type with color capabilities.
610 .It Ev TZ
611 The timezone to use when displaying dates.
612 See
613 .Xr environ 7
614 for more information.
615 .El
616 .Sh COMPATIBILITY
617 The group field is now automatically included in the long listing for
618 files in order to be compatible with the
619 .St -p1003.2
620 specification.
621 .Sh SEE ALSO
622 .Xr chflags 1 ,
623 .Xr chmod 1 ,
624 .Xr sort 1 ,
625 .Xr xterm 1 Pq Pa x11/xterm ,
626 .Xr termcap 5 ,
627 .Xr symlink 7 ,
628 .Xr sticky 8
629 .Sh STANDARDS
630 With the exception of options
631 .Fl g ,
632 .Fl n
633 and
634 .Fl o ,
635 the
636 .Nm
637 utility conforms to
638 .St -p1003.1-2001 .
639 .Sh HISTORY
640 An
641 .Nm
642 command appeared in
643 .At v1 .
644 .Sh BUGS
645 To maintain backward compatibility, the relationships between the many
646 options are quite complex.