BSD 3 development
[unix-history] / usr / man / man1 / ls.1
CommitLineData
1f6fd1a3
BJ
1.TH LS 1 11/16/79
2.UC
3.SH NAME
4ls \- list contents of directory
5.SH SYNOPSIS
6.B ls
7[
8.B \-ltasdruifgm1cqx
9] name ...
10.br
11.B l
12[ \fIls\fR options ] name ...
13.SH DESCRIPTION
14For each directory argument,
15.I ls
16lists the contents of the directory;
17for each file argument,
18.I ls
19repeats its name and any other information requested.
20The output is sorted alphabetically by default.
21When no argument is given, the current directory is listed.
22When several arguments are given,
23the arguments are first sorted appropriately,
24but file arguments appear
25before directories and their contents.
26.PP
27There are three possible listing formats.
28The format chosen depends on whether the output is going
29to a teletype, and may also be controlled by option flags.
30The default format for a teletype is to list the contents of directories
31in multi-column format, with the entries sorted down the columns.
32(See also the
33.B \-x
34option below.)
35If the standard output is not a teletype, the default format is to
36list one entry per line.
37Finally, there is a stream output format in which files are listed
38across the page, separated by `,' characters.
39The
40.B \-m
41flag enables this format.
42.PP
43When invoked as
44.I l
45the default is
46.B \-m .
47.PP
48.B "Note:"
49Files which are not the contents of a directory being interpreted
50are always sorted across the page rather than down the page in columns.
51This is because the individual file names may be arbitrarily long.
52There are several options:
53.TP
54.B \-l
55List in long format, giving mode, number of links, owner,
56size in bytes, and time of last modification
57for each file.
58(See below.)
59If the file is a special file the size field will instead contain
60the major and minor device numbers.
61.TP
62.B \-t
63Sort by time modified (latest first) instead of
64by name, as is normal.
65.TP
66.B \-a
67List all entries; usually
68.RB ` . '
69and
70.RB ` .. '
71are suppressed.
72.TP
73.B \-s
74Give size in blocks,
75including indirect blocks, for each entry.
76.TP
77.B \-d
78If argument is a directory, list only its name, not
79its contents (mostly used with
80.B \-l
81to get status
82on directory).
83.TP
84.B \-r
85Reverse the order of sort to get reverse alphabetic
86or oldest first as appropriate.
87.TP
88.B \-u
89Use time of last access instead of last
90modification for sorting
91.RB ( \-t )
92or printing
93.RB ( \-l ).
94.TP
95.B \-i
96Print i-number in first column
97of the report for each file listed.
98.TP
99.B \-f
100Force each argument to be interpreted as a directory
101and list the name found in each slot.
102This option turns off
103.B "\-l, \-t, \-s,"
104and
105.B \-r,
106and
107turns on
108.B \-a;
109the order is the order in which entries
110appear in the directory.
111.TP
112.B \-g
113Give group ID instead of owner ID in long listing.
114.TP
115.B \-m
116force stream output format
117.TP
118.B \-1
119force one entry per line output format, e.g. to a teletype
120.TP
121.B \-c
122force multi-column output, e.g. to a file or a pipe
123.TP
124.B \-q
125force printing of non-graphic characters in file names as
126the character `?'; this normally happens only if the output device is
127a teletype
128.TP
129.B \-x
130force columnar printing to be sorted across rather than
131down the page;
132this is the default if the last character of the name the program is invoked
133with is an `x'.
134.PP
135The mode printed under the
136.B \-l
137option contains 11 characters
138which are interpreted
139as follows:
140the first character is
141.TP 3
142.B d
143if the entry is a directory;
144.br
145.ns
146.TP 3
147.B b
148if the entry is a block-type special file;
149.br
150.ns
151.TP 3
152.B c
153if the entry is a character-type special file;
154.br
155.ns
156.TP 3
157.B \-
158if the entry is a plain file.
159.PP
160The next 9 characters are interpreted
161as three sets of three bits each.
162The first set refers to owner permissions;
163the next to permissions to others in the same user-group;
164and the last to all others.
165Within each set the three characters indicate
166permission respectively to read, to write, or to
167execute the file as a program.
168For a directory, `execute' permission is interpreted
169to mean permission to search the directory
170for a specified file.
171The permissions are indicated as follows:
172.TP 3
173.B r
174if the file is readable;
175.br
176.ns
177.TP 3
178.B w
179if the file is writable;
180.br
181.ns
182.TP 3
183.B x
184if the file is executable;
185.br
186.ns
187.TP 3
188.B \-
189if the indicated permission is not granted.
190.PP
191The group-execute permission character is given
192as
193.B s
194if the file has set-group-ID mode;
195likewise the user-execute permission character is given
196as
197.B s
198if the file has set-user-ID mode.
199.PP
200The last character of the mode (normally `x' or `\-') is
201.B t
202if the 1000 bit of the mode is on.
203See
204.IR chmod (1)
205for the meaning of this mode.
206.PP
207When the sizes of the files in a directory
208are listed, a total count of blocks,
209including indirect blocks is printed.
210.SH FILES
211/etc/passwd to get user ID's for
212`ls \-l'.
213.br
214/etc/group to get group ID's for
215`ls \-g'.
216.SH BUGS
217Newline and tab are considered printing characters in file names.
218.PP
219The output device is assumed to be 80 columns wide.
220Columns are basically 15 characters wide, 20 characters wide if
221.BR \-i " or " "\-s\fR is specified, 25 characters wide if both"
222.BR \-i " and " "\-s\fR are specified."
223In any case where
224.BR \-l ""
225or
226.BR \-n ""
227is specified, we assume
228only one entry will fit per line.
229.PP
230The option setting based on whether the output is a teletype is
231undesirable as:
232.PP
233.DT
234 ls \-s | lpr
235.PP
236is much different than
237.PP
238 ls \-s
239.PP
240On the other hand, not doing this setting would make old shell scripts
241which used
242.I ls
243almost certain losers,
244and then one could no longer do, e.g.:
245.PP
246 ls \-s | sort \-nr
247.PP
248but would have to do
249.PP
250 ls \-s \-1 | sort \-nr
251.PP
252Column widths choices are poor for terminals which can tab.