xref: /freebsd/bin/ls/ls.1 (revision a8445737e740901f5f2c8d24c12ef7fc8b00134e)
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.\"	$Id: ls.1,v 1.23 1998/05/15 06:22:30 charnier Exp $
37.\"
38.Dd July 29, 1994
39.Dt LS 1
40.Os
41.Sh NAME
42.Nm ls
43.Nd list directory contents
44.Sh SYNOPSIS
45.Nm ls
46.Op Fl ABCFHLPRTWabcdfgikloqrstu1
47.Op Ar file ...
48.Sh DESCRIPTION
49For each operand that names a
50.Ar file
51of a type other than
52directory,
53.Nm
54displays its name as well as any requested,
55associated information.
56For each operand that names a
57.Ar file
58of type directory,
59.Nm
60displays the names of files contained
61within that directory, as well as any requested, associated
62information.
63.Pp
64If no operands are given, the contents of the current
65directory are displayed.
66If more than one operand is given,
67non-directory operands are displayed first; directory
68and non-directory operands are sorted separately and in
69lexicographical order.
70.Pp
71The following options are available:
72.Bl -tag -width indent
73.It Fl A
74List all entries except for
75.Ql \&.
76and
77.Ql \&.. .
78Always set for the super-user.
79.It Fl B
80Force printing of non-graphic characters in file names as \\xxx,
81where xxx is the numeric value of the character in octal.
82.It Fl C
83Force multi-column output; this is the default when output is to a terminal.
84.It Fl F
85Display a slash (/) immediately after each pathname
86that is a directory, an asterisk (*) after each that is
87executable,
88an at sign (@) after each symbolic link,
89an equals sign (=) after each socket,
90a percent sign (%) after each whiteout,
91and a vertical bar (|) after each that is a
92.Tn FIFO .
93.It Fl H
94Symbolic links on the command line are followed.  This option is assumed if
95none of the
96.Fl F ,
97.Fl d ,
98or
99.Fl l
100options are specified.
101.It Fl L
102If argument is a symbolic link, list the file or directory the link references
103rather than the link itself. This option cancels the
104.Fl P
105option.
106.It Fl P
107If argument is a symbolic link, list the link itself rather than the
108object the link references.  This option cancels the
109.Fl H
110and
111.Fl L
112options.
113.It Fl R
114Recursively list subdirectories encountered.
115.It Fl T
116Display complete time information for the file, including
117month, day, hour, minute, second, and year.
118.It Fl W
119Display whiteouts when scanning directories.
120.It Fl a
121Include directory entries whose names begin with a
122dot (.).
123.It Fl b
124As
125.Fl B ,
126but use C escape codes whenever possible.
127.It Fl c
128Use time when file status was last changed for sorting or printing.
129.It Fl d
130Directories are listed as plain files (not searched recursively).
131.It Fl f
132Output is not sorted.
133.It Fl g
134This option is deprecated and is only available for compatibility
135with
136.Bx 4.3 ;
137it was used to display the group name in the long
138.Pq Fl l
139format output.
140.It Fl i
141For each file, print the file's file serial number (inode number).
142.It Fl k
143If the
144.Fl s
145option is specified, print the file size allocation in kilobytes,
146not blocks.  This option overrides the environment variable BLOCKSIZE.
147.It Fl l
148(The lowercase letter ``ell.'')  List in long format. (See below.)
149If the output is to a terminal, a total sum for all the file
150sizes is output on a line before the long listing.
151.It Fl o
152Include the file flags in a long
153.Pq Fl l
154output.
155.It Fl q
156Force printing of non-graphic characters in file names as
157the character `?'; this is the default when output is to a terminal.
158.It Fl r
159Reverse the order of the sort to get reverse
160lexicographical order or the oldest entries first.
161.It Fl s
162Display the number of file system blocks actually used by each file, in units
163of 512 bytes, where partial units are rounded up to the next integer value.
164If the output is to a terminal, a total sum for all the file
165sizes is output on a line before the listing.  The environment variable
166BLOCKSIZE overrides the unit size of 512 bytes.
167.It Fl t
168Sort by time modified (most recently modified
169first) before sorting the operands by lexicographical
170order.
171.It Fl u
172Use time of last access,
173instead of last modification
174of the file for sorting
175.Pq Fl t
176or printing
177.Pq Fl l .
178.It Fl \&1
179(The numeric digit ``one.'')  Force output to be
180one entry per line.
181This is the default when
182output is not to a terminal.
183.El
184.Pp
185The
186.Fl 1 ,
187.Fl C ,
188and
189.Fl l
190options all override each other; the last one specified determines
191the format used.
192.Pp
193The
194.Fl c
195and
196.Fl u
197options override each other; the last one specified determines
198the file time used.
199.Pp
200The
201.Fl B ,
202.Fl b
203and
204.Fl q
205options all override each other; the last one specified determines
206the format used for non-printable characters.
207.Pp
208The
209.Fl H,
210.Fl L
211and
212.Fl P
213options all override each other (either partially or fully); they
214are applied in the order specified.
215.Pp
216By default,
217.Nm
218lists one entry per line to standard
219output; the exceptions are to terminals or when the
220.Fl C
221option is specified.
222.Pp
223File information is displayed with one or more
224<blank>s separating the information associated with the
225.Fl i ,
226.Fl s ,
227and
228.Fl l
229options.
230.Ss The Long Format
231If the
232.Fl l
233option is given, the following information
234is displayed for each file:
235file mode,
236number of links, owner name, group name,
237number of bytes in the file, abbreviated
238month, day-of-month file was last modified,
239hour file last modified, minute file last
240modified, and the pathname.
241In addition, for each directory whose contents are displayed, the total
242number of 512-byte blocks used by the files in the directory is displayed
243on a line by itself immediately before the information for the files in the
244directory.
245.Pp
246If the modification time of the file is more than 6 months
247in the past or future, then the year of the last modification
248is displayed in place of the hour and minute fields.
249.Pp
250If the owner or group names are not a known user or group name
251the numeric ID's are displayed.
252.Pp
253If the file is a character special or block special file,
254the major and minor device numbers for the file are displayed
255in the size field. If the file is a symbolic link the pathname of the
256linked-to file is preceded by
257.Dq \-> .
258.Pp
259The file mode printed under the
260.Fl l
261option consists of the
262entry type, owner permissions, and group permissions.
263The entry type character describes the type of file, as
264follows:
265.Pp
266.Bl -tag -width 4n -offset indent -compact
267.It Sy b
268Block special file.
269.It Sy c
270Character special file.
271.It Sy d
272Directory.
273.It Sy l
274Symbolic link.
275.It Sy s
276Socket link.
277.It Sy p
278.Tn FIFO .
279.It Sy \-
280Regular file.
281.El
282.Pp
283The next three fields
284are three characters each:
285owner permissions,
286group permissions, and
287other permissions.
288Each field has three character positions:
289.Bl -enum -offset indent
290.It
291If
292.Sy r ,
293the file is readable; if
294.Sy \- ,
295it is not readable.
296.It
297If
298.Sy w ,
299the file is writable; if
300.Sy \- ,
301it is not writable.
302.It
303The first of the following that applies:
304.Bl -tag -width 4n -offset indent
305.It Sy S
306If in the owner permissions, the file is not executable and
307set-user-ID mode is set.
308If in the group permissions, the file is not executable
309and set-group-ID mode is set.
310.It Sy s
311If in the owner permissions, the file is executable
312and set-user-ID mode is set.
313If in the group permissions, the file is executable
314and setgroup-ID mode is set.
315.It Sy x
316The file is executable or the directory is
317searchable.
318.It Sy \-
319The file is neither readable, writable, executable,
320nor set-user-ID nor set-group-ID mode, nor sticky. (See below.)
321.El
322.Pp
323These next two apply only to the third character in the last group
324(other permissions).
325.Bl -tag -width 4n -offset indent
326.It Sy T
327The sticky bit is set
328(mode
329.Li 1000 ) ,
330but not execute or search permission. (See
331.Xr chmod 1
332or
333.Xr sticky 8 . )
334.It Sy t
335The sticky bit is set (mode
336.Li 1000 ) ,
337and is searchable or executable.
338(See
339.Xr chmod 1
340or
341.Xr sticky 8 . )
342.El
343.El
344.Pp
345The
346.Nm
347utility exits 0 on success, and >0 if an error occurs.
348.Sh ENVIRONMENT
349The following environment variables affect the execution of
350.Nm Ns :
351.Bl -tag -width BLOCKSIZE
352.It Ev BLOCKSIZE
353If the environment variable
354.Ev BLOCKSIZE
355is set, the block counts
356(see
357.Fl s )
358will be displayed in units of that size block.
359.It COLUMNS
360If this variable contains a string representing a
361decimal integer, it is used as the
362column position width for displaying
363multiple-text-column output.
364The
365.Nm
366utility calculates how
367many pathname text columns to display
368based on the width provided.
369(See
370.Fl C . )
371.It Ev TZ
372The timezone to use when displaying dates.
373See
374.Xr environ 7
375for more information.
376.It Ev LS_COLWIDTHS
377If this variable is set, it is considered to be a
378colon-delimited list of minimum column widths.  Unreasonable
379and insufficient widths are ignored (thus zero signifies
380a dynamically sized column).  Not all
381columns have changable widths.  The fields are,
382in order: inode, block count, number of links, user name,
383group name, flags, file size, file name.
384.El
385.Sh COMPATIBILITY
386The group field is now automatically included in the long listing for
387files in order to be compatible with the
388.St -p1003.2
389specification.
390.Sh SEE ALSO
391.Xr chmod 1 ,
392.Xr symlink 7 ,
393.Xr sticky 8
394.Sh HISTORY
395An
396.Nm
397command appeared in
398.At v1 .
399.Sh STANDARDS
400The
401.Nm
402function is expected to be a superset of the
403.St -p1003.2
404specification.
405.Sh BUGS
406To maintain backward compatibility, the relationships between the many
407options is quite complex.
408
409