xref: /netbsd-src/bin/ls/ls.1 (revision ce2c90c7c172d95d2402a5b3d96d8f8e6d138a21)
1.\"	$NetBSD: ls.1,v 1.62 2006/09/22 23:00:32 elad Exp $
2.\"
3.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the Institute of Electrical and Electronics Engineers, Inc.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"     @(#)ls.1	8.7 (Berkeley) 7/29/94
34.\"
35.Dd September 23, 2006
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 AaBbCcdFfghikLlmnopqRrSsTtuWwx1
44.Op Ar
45.Sh DESCRIPTION
46For each operand that names a
47.Ar file
48of a type other than
49directory,
50.Nm
51displays its name as well as any requested,
52associated information.
53For each operand that names a
54.Ar file
55of type directory,
56.Nm
57displays the names of files contained
58within that directory, as well as any requested, associated
59information.
60.Pp
61If no operands are given, the contents of the current
62directory are displayed.
63If more than one operand is given,
64non-directory operands are displayed first; directory
65and non-directory operands are sorted separately and in
66lexicographical order.
67.Pp
68The following options are available:
69.Bl -tag -width indent
70.It Fl A
71List all entries except for
72.Ql \&.
73and
74.Ql \&.. .
75Always set for the super-user.
76.It Fl a
77Include directory entries whose names begin with a
78dot
79.Pq Sq \&. .
80.It Fl B
81Force printing of non-graphic characters in file names as \\xxx, where xxx
82is the numeric value of the character in octal.
83.It Fl b
84As
85.Fl B ,
86but use C escape codes whenever possible.
87.It Fl C
88Force multi-column output; this is the default when output is to a terminal.
89.It Fl c
90Use time when file status was last changed,
91instead of time of last modification of the file for sorting
92.Pq Fl t
93or printing
94.Pq Fl l .
95.It Fl d
96Directories are listed as plain files (not searched recursively) and
97symbolic links in the argument list are not indirected through.
98.It Fl F
99Display a slash
100.Pq Sq \&/
101immediately after each pathname that is a directory,
102an asterisk
103.Pq Sq \&*
104after each that is executable,
105an at sign
106.Pq Sq \&@
107after each symbolic link,
108a percent sign
109.Pq Sq \&%
110after each whiteout,
111an equal sign
112.Pq Sq \&=
113after each socket,
114and a vertical bar
115.Pq Sq \&|
116after each that is a
117.Tn FIFO .
118.It Fl f
119Output is not sorted.
120.It Fl g
121The same as
122.Fl l ,
123except that the owner is not printed.
124.It Fl h
125Modifies the
126.Fl s
127and
128.Fl l
129options, causing the sizes to be reported in bytes displayed in a human
130readable format.
131Overrides
132.Fl k .
133.It Fl i
134For each file, print the file's file serial number (inode number).
135.It Fl k
136Modifies the
137.Fl s
138option, causing the sizes to be reported in kilobytes.
139The rightmost of the
140.Fl k
141and
142.Fl h
143flags overrides the previous flag.
144See also
145.Fl h .
146.It Fl L
147For each file, if it's a link, evaluate file information and file type
148of the referenced file and not the link itself; however still print
149the link name, unless used with
150.Fl l ,
151for example.
152.It Fl l
153(The lowercase letter
154.Dq ell ) .
155List in long format.
156(See below.)
157A total sum for all the file sizes is output on a line before the long
158listing.
159.It Fl m
160Stream output format; list files across the page, separated by commas.
161.It Fl n
162Display the user and group IDs numerically rather than converting
163to a user or group name in a long
164.Pq Fl l
165output.
166.It Fl o
167Include the file flags in a long
168.Pq Fl l
169output.
170If no file flags are set,
171.Dq -
172is displayed.
173(See
174.Xr chflags 1
175for a list of possible flags and their meanings.)
176.It Fl p
177Display a slash
178.Pq Sq \&/
179immediately after each pathname that is a directory.
180.It Fl q
181Force printing of non-printable characters in file names as
182the character
183.Sq \&? ;
184this is the default when output is to a terminal.
185.It Fl R
186Recursively list subdirectories encountered.
187.It Fl r
188Reverse the order of the sort to get reverse
189lexicographical order or the smallest or oldest entries first.
190.It Fl S
191Sort by size, largest file first.
192.It Fl s
193Display the number of file system blocks actually used by each file, in units
194of 512 bytes or
195.Ev BLOCKSIZE
196(see
197.Sx ENVIRONMENT )
198where partial units are rounded up to the
199next integer value.
200If the output is to a terminal, a total sum for all the file
201sizes is output on a line before the listing.
202.It Fl T
203When used with the
204.Fl l
205(the lowercase letter
206.Dq ell )
207option, display complete time information for the file, including
208month, day, hour, minute, second, and year.
209.It Fl t
210Sort by time modified (most recently modified
211first) before sorting the operands by lexicographical
212order.
213.It Fl u
214Use time of last access,
215instead of last modification
216of the file for sorting
217.Pq Fl t
218or printing
219.Pq Fl l .
220.It Fl W
221Display whiteouts when scanning directories.
222.It Fl w
223Force raw printing of non-printable characters.
224This is the default when output is not to a terminal.
225.It Fl x
226Multi-column output sorted across the page rather than down the page.
227.It Fl \&1
228(The numeric digit
229.Dq one ) .
230Force output to be one entry per line.
231This is the default when output is not to a terminal.
232.El
233.Pp
234The
235.Fl B ,
236.Fl b ,
237.Fl w ,
238and
239.Fl q
240options all override each other; the last one specified determines
241the format used for non-printable characters.
242.Pp
243The
244.Fl 1 ,
245.Fl C ,
246.Fl g ,
247.Fl l ,
248.Fl m ,
249and
250.Fl x
251options all override each other; the last one specified determines
252the format used with the exception that if both
253.Fl l
254and
255.Fl g
256are specified,
257.Fl l
258will always override
259.Fl g ,
260even if
261.Fl g
262was specified last.
263.Pp
264The
265.Fl c
266and
267.Fl u
268options override each other; the last one specified determines
269the file time used.
270.Pp
271By default,
272.Nm
273lists one entry per line to standard
274output; the exceptions are to terminals or when the
275.Fl C
276or
277.Fl m
278options are specified.
279.Pp
280File information is displayed with one or more
281.Aq blank
282separating the information associated with the
283.Fl i ,
284.Fl s ,
285and
286.Fl l
287options.
288.Ss The Long Format
289If the
290.Fl l
291option is given, the following information
292is displayed for each file:
293.Bl -item -offset indent -compact
294.It
295file mode
296.It
297number of links
298.It
299owner name
300.It
301group name
302.It
303file flags (if
304.Fl o
305given)
306.It
307number of bytes in the file
308.It
309abbreviated month file was last modified
310.It
311day-of-month file was last modified
312.It
313hour and minute file was last modified
314.It
315pathname
316.El
317.Pp
318In addition, for each directory whose contents are displayed, the total
319number of 512-byte blocks used by the files in the directory is displayed
320on a line by itself immediately before the information for the files in the
321directory.
322.Pp
323If the owner or group names are not a known user or group name,
324or the
325.Fl n
326option is given,
327the numeric ID's are displayed.
328.Pp
329If the file is a character special or block special file,
330the major and minor device numbers for the file are displayed
331in the size field.
332If the file is a symbolic link the pathname of the
333linked-to file is preceded by
334.Dq \-\*[Gt] .
335.Pp
336The file mode printed under the
337.Fl l
338option consists of the entry type, owner permissions, group
339permissions, and other permissions.
340The entry type character describes the type of file, as
341follows:
342.Pp
343.Bl -tag -width 4n -offset indent -compact
344.It Sy a
345Archive state 1.
346.It Sy A
347Archive state 2.
348.It Sy b
349Block special file.
350.It Sy c
351Character special file.
352.It Sy d
353Directory.
354.It Sy l
355Symbolic link.
356.It Sy s
357Socket link.
358.It Sy p
359FIFO.
360.It Sy w
361Whiteout.
362.It Sy \-
363Regular file.
364.El
365.Pp
366The next three fields
367are three characters each:
368owner permissions,
369group permissions, and
370other permissions.
371Each field has three character positions:
372.Bl -enum -offset indent
373.It
374If
375.Sy r ,
376the file is readable; if
377.Sy \- ,
378it is not readable.
379.It
380If
381.Sy w ,
382the file is writable; if
383.Sy \- ,
384it is not writable.
385.It
386The first of the following that applies:
387.Bl -tag -width 4n -offset indent
388.It Sy S
389If in the owner permissions, the file is not executable and
390set-user-ID mode is set.
391If in the group permissions, the file is not executable
392and set-group-ID mode is set.
393.It Sy s
394If in the owner permissions, the file is executable
395and set-user-ID mode is set.
396If in the group permissions, the file is executable
397and setgroup-ID mode is set.
398.It Sy x
399The file is executable or the directory is
400searchable.
401.It Sy \-
402The file is neither readable, writable, executable,
403nor set-user-ID nor set-group-ID mode, nor sticky.
404(See below.)
405.El
406.Pp
407These next two apply only to the third character in the last group
408(other permissions).
409.Bl -tag -width 4n -offset indent
410.It Sy T
411The sticky bit is set
412(mode
413.Li 1000 ) ,
414but not execute or search permission.
415(See
416.Xr chmod 1
417or
418.Xr sticky 7 . )
419.It Sy t
420The sticky bit is set (mode
421.Li 1000 ) ,
422and is searchable or executable.
423(See
424.Xr chmod 1
425or
426.Xr sticky 7 . )
427.El
428.El
429.Pp
430The number of bytes displayed for a directory is a function of the
431number of
432.Xr dirent 5
433structures in the directory, not all of which may be allocated to
434any existing file.
435.Sh EXIT STATUS
436The
437.Nm
438utility exits 0 on success, and \*[Gt]0 if an error occurs.
439.Sh ENVIRONMENT
440The following environment variables affect the execution of
441.Nm :
442.Bl -tag -width BLOCKSIZE
443.It Ev BLOCKSIZE
444If the environment variable
445.Ev BLOCKSIZE
446is set, and the
447.Fl h
448and
449.Fl k
450options are not specified, the block counts
451(see
452.Fl s )
453will be displayed in units of that size block.
454.It Ev COLUMNS
455If this variable contains a string representing a
456decimal integer, it is used as the
457column position width for displaying
458multiple-text-column output.
459The
460.Nm
461utility calculates how
462many pathname text columns to display
463based on the width provided.
464(See
465.Fl C . )
466.It Ev TZ
467The timezone to use when displaying dates.
468See
469.Xr environ 7
470for more information.
471.El
472.Sh COMPATIBILITY
473The group field is now automatically included in the long listing for
474files in order to be compatible with the
475.St -p1003.2
476specification.
477.Sh SEE ALSO
478.Xr chflags 1 ,
479.Xr chmod 1 ,
480.Xr stat 2 ,
481.Xr getbsize 3 ,
482.Xr dir 5 ,
483.Xr sticky 7 ,
484.Xr symlink 7
485.Sh STANDARDS
486The
487.Nm
488utility is expected to be a superset of the
489.St -p1003.2
490specification.
491.Sh HISTORY
492An
493.Nm
494utility appeared in
495.At v5 .
496