BSD 1 development
[unix-history] / man6 / ls.6
CommitLineData
bb3f0319
BJ
1.th LS VI 9/3/77
2.sh NAME
3ls \- list contents of directory
4.sh SYNOPSIS
5.bd ls
6[
7.bd \-lntasdruifm1cqx
8] name ...
9.sh DESCRIPTION
10For each directory argument,
11.it ls
12lists the contents of the directory;
13for each file argument,
14.it ls
15repeats its name and any other information requested.
16The output is sorted alphabetically by default.
17When no argument is given, the current directory is listed.
18When several arguments are given,
19the arguments are first sorted appropriately,
20but file arguments appear
21before directories and their contents.
22.s3
23.it Ls
24has three possible listing formats.
25The format chosen depends on whether the output is going
26to a teletype, and may also be controlled by option flags.
27The default format for a teletype is to list the contents of directories
28in multi-column format, with the entries sorted down the columns.
29(See also the
30.bd \-x
31option below.)
32If the standard output is not a teletype, the default format is to
33list one entry per line.
34This is the way older versions of
35.it ls
36worked.
37Finally, there is a stream output format in which files are listed
38across the page, separated by `,' characters.
39The
40.bd \-m
41flag enables this format.
42.s3
43.bd "Important note:"
44Files which are not the contents of a directory being interpreted
45are always sorted across the page rather than down the page in columns.
46This is because the individual file names may be arbitrarily long.
47.s3
48There are scads of options:
49.s3
50.lp +4 4
51\fB\-l\fR list in long format, giving mode, number of links, owner,
52size in bytes, and time of last modification
53for each file.
54(See below.)
55If the file is a special file the size field will instead contain
56the major and minor device numbers.
57.s3
58.lp +4 4
59\fB\-n\fR long format like \fB\-l\fR but without looking up the string
60name of the owner; the owner is given as decimal group and user id.
61This is much faster on a system with a large password file when many
62different people own the files being
63listed.
64.s3
65.lp +4 4
66\fB\-t\fR sort by time modified (latest first) instead of
67by name, as is normal
68.s3
69.lp +4 4
70\fB\-a\fR list all entries; usually those beginning with `\fB.\fR' are
71suppressed
72.s3
73.lp +4 4
74\fB\-s\fR give size in blocks for each entry.
75If l is also specified the size in blocks
76appears after the size in bytes.
77.s3
78.lp +4 4
79\fB\-d\fR if argument is a directory, list only its name, not
80its contents (mostly used with
81.bd \-l
82to get status
83on directory)
84.s3
85.lp +4 4
86\fB\-r\fR reverse the order of sort to get reverse alphabetic
87or oldest first as appropriate
88.s3
89.lp +4 4
90\fB\-u\fR use time of last access instead of last
91modification for sorting (\fB\-t\fR) or printing
92(\fB\-l\fR)
93.s3
94.lp +4 4
95\fB\-i\fR print i-number in first column
96of the report for each file listed
97.s3
98.lp +4 4
99\fB\-f\fR force each argument to be interpreted as a directory
100and list the name found in each slot.
101This option turns off
102.bd \-l,
103.bd \-t,
104.bd \-s,
105and
106.bd \-r,
107and
108turns on
109.bd \-a;
110the order is the order in which entries
111appear in the directory.
112.s3
113.lp +4 4
114\fB\-m\fR force stream output format
115.s3
116.lp +4 4
117\fB\-1\fR force one entry per line output format, e.g. to a teletype
118.s3
119.lp +4 4
120\fB\-c\fR force multi-column output, e.g. to a file or a pipe
121.s3
122.lp +4 4
123\fB\-q\fR force printing of non-graphic characters in file names as
124the character `?'; this normally happens only if the output device is
125a teletype
126.s3
127.lp +4 4
128\fB\-x\fR force columnar printing to be sorted across rather than
129down the page;
130this is the default if the last character of the name the program is invoked
131with is not an `l' or an `s'.
132.s3
133.i0
134The mode printed under the
135.bd \-l
136option contains 7 characters
137which are interpreted
138as follows:
139the first character is
140.s3
141.lp +3 3
142\fBd\fR if the entry is a directory;
143.lp +3 3
144\fBq\fR if the entry is a quota file;
145.lp +3 3
146\fBb\fR if the entry is a block-type special file;
147.lp +3 3
148\fBc\fR if the entry is a character-type special file;
149.lp +3 3
150\fB\-\fR if the entry is a plain file.
151.s3
152.i0
153The next 6 characters are interpreted
154as two sets of three bits each.
155The first set refers to owner permissions;
156and the second to others.
157Within each set the three characters indicate
158permission respectively to read, to write, or to
159execute the file as a program.
160For a directory, `execute' permission is interpreted
161to mean permission to search the directory
162for a specified file.
163The permissions are indicated as follows:
164.s3
165.lp +3 3
166\fBr\fR if the file is readable
167.lp +3 3
168\fBw\fR if the file is writable
169.lp +3 3
170\fBx\fR if the file is executable
171.lp +3 3
172\fB\-\fR if the indicated permission is not granted
173.s3
174.i0
175The user-execute permission character is given
176as
177.bd s
178if the file has set-user-ID mode.
179.s3
180The last character of the mode is printed as
181``t'' if the 1000 bit of the mode is on.
182See
183.it "chmod (I)"
184for the current meaning of this mode.
185.sh FILES
186/etc/passwd to get user ID's for
187\fBls \-l\fR.
188.sh BUGS
189Newline and tab are considered printing characters in file names.
190.s3
191Output device is assumed to be 80 columns wide.
192Columns are basically 15 characters wide, 20 characters wide if
193\fB\-i\fR or \fB\-s\fR is specified, 25 characters wide if both
194\fB\-i\fR and \fB\-s\fR are specified.
195In any case where \fB\-l\fR or \fB\-n\fR is specified, we assume
196only one entry will fit per line.
197.s3
198The option setting based on whether the output is a teletype is
199undesirable as:
200.s3
201.dt
202 ls \-s | lpr
203.s3
204is much different than
205.s3
206 ls \-s
207.s3
208On the other hand, not doing this setting would make old shell scripts
209which used
210.it ls
211almost certain losers,
212and then one could no longer do, e.g.:
213.s3
214 ls \-s | sort \-nr
215.s3
216but would have to do
217.s3
218 ls \-s \-1 | sort \-nr