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