1LS(P)                      POSIX Programmer's Manual                     LS(P)
2
3
4

NAME

6       ls - list directory contents
7

SYNOPSIS

9       ls [-CFRacdilqrtu1][-H | -L ][-fgmnopsx][file...]
10

DESCRIPTION

12       For  each  operand  that names a file of a type other than directory or
13       symbolic link to a directory, ls shall write the name of  the  file  as
14       well  as  any requested, associated information.  For each operand that
15       names a file of type directory, ls shall write the names of files  con‐
16       tained within the directory as well as any requested, associated infor‐
17       mation. If one of the -d, -F, or -l options are specified, and  one  of
18       the  -H  or -L options are not specified, for each operand that names a
19       file of type symbolic link to a directory, ls shall write the  name  of
20       the  file  as well as any requested, associated information. If none of
21       the -d, -F, or -l options are specified, or the -H or  -L  options  are
22       specified,  for each operand that names a file of type symbolic link to
23       a directory, ls shall write the names of  files  contained  within  the
24       directory as well as any requested, associated information.
25
26       If  no  operands are specified, ls shall write the contents of the cur‐
27       rent directory. If more than one operand is specified, ls  shall  write
28       non-directory operands first; it shall sort directory and non-directory
29       operands separately according to the collating sequence in the  current
30       locale.
31
32       The  ls utility shall detect infinite loops; that is, entering a previ‐
33       ously visited directory that is an ancestor of the  last  file  encoun‐
34       tered.  When  it  detects an infinite loop, ls shall write a diagnostic
35       message to standard error and shall either recover its position in  the
36       hierarchy or terminate.
37

OPTIONS

39       The  ls  utility  shall  conform  to  the  Base  Definitions  volume of
40       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
41
42       The following options shall be supported:
43
44       -C     Write multi-text-column output with entries sorted down the col‐
45              umns,  according  to  the collating sequence. The number of text
46              columns and the column separator characters are unspecified, but
47              should be adapted to the nature of the output device.
48
49       -F     Do  not follow symbolic links named as operands unless the -H or
50              -L options are specified. Write a  slash  (  '/'  )  immediately
51              after  each  pathname  that  is a directory, an asterisk ( '*' )
52              after each that is executable, a vertical bar ( '|' ) after each
53              that is a FIFO, and an at sign ( '@' ) after each that is a sym‐
54              bolic link. For other file types, other symbols may be written.
55
56       -H     If a symbolic link referencing a file of type directory is spec‐
57              ified  on  the command line, ls shall evaluate the file informa‐
58              tion and file type to be those of the  file  referenced  by  the
59              link,  and not the link itself; however, ls shall write the name
60              of the link itself and not the file referenced by the link.
61
62       -L     Evaluate the file information and file  type  for  all  symbolic
63              links  (whether  named  on  the command line or encountered in a
64              file hierarchy) to be those of the file referenced by the  link,
65              and not the link itself; however, ls shall write the name of the
66              link itself and not the file referenced by the link. When -L  is
67              used  with  -l, write the contents of symbolic links in the long
68              format (see the STDOUT section).
69
70       -R     Recursively list subdirectories encountered.
71
72       -a     Write out all directory entries,  including  those  whose  names
73              begin  with  a  period  ( '.' ). Entries beginning with a period
74              shall not be written out unless explicitly  referenced,  the  -a
75              option is supplied, or an implementation-defined condition shall
76              cause them to be written.
77
78       -c     Use time of last modification of  the  file  status  information
79              (see   <sys/stat.h>   in   the   System   Interfaces  volume  of
80              IEEE Std 1003.1-2001) instead of last modification of  the  file
81              itself for sorting ( -t) or writing ( -l).
82
83       -d     Do  not follow symbolic links named as operands unless the -H or
84              -L options are specified. Do not treat  directories  differently
85              than  other  types  of  files.  The  use  of -d with -R produces
86              unspecified results.
87
88       -f     Force each argument to be interpreted as a  directory  and  list
89              the  name found in each slot. This option shall turn off -l, -t,
90              -s, and -r, and shall turn on -a; the  order  is  the  order  in
91              which entries appear in the directory.
92
93       -g     The same as -l, except that the owner shall not be written.
94
95       -i     For  each  file, write the file's file serial number (see stat()
96              in the System Interfaces volume of IEEE Std 1003.1-2001).
97
98       -l     (The letter ell.) Do not follow symbolic links named as operands
99              unless  the  -H  or  -L options are specified. Write out in long
100              format (see the STDOUT section). When -l (ell) is specified,  -1
101              (one) shall be assumed.
102
103       -m     Stream  output  format; list files across the page, separated by
104              commas.
105
106       -n     The same as -l, except that the  owner's  UID  and  GID  numbers
107              shall be written, rather than the associated character strings.
108
109       -o     The same as -l, except that the group shall not be written.
110
111       -p     Write  a  slash  (  '/'  ) after each filename if that file is a
112              directory.
113
114       -q     Force each instance of  non-printable  filename  characters  and
115              <tab>s  to  be  written  as the question-mark ( '?' ) character.
116              Implementations may provide this option by default if the output
117              is to a terminal device.
118
119       -r     Reverse  the order of the sort to get reverse collating sequence
120              or oldest first.
121
122       -s     Indicate the total number of file system blocks consumed by each
123              file displayed. The block size is implementation-defined.
124
125       -t     Sort  with  the  primary  key being time modified (most recently
126              modified first) and the secondary key being filename in the col‐
127              lating sequence.
128
129       -u     Use time of last access (see <sys/stat.h>) instead of last modi‐
130              fication of the file for sorting ( -t) or writing ( -l).
131
132       -x     The same as -C, except that the multi-text-column output is pro‐
133              duced with entries sorted across, rather than down, the columns.
134
135       -1     (The numeric digit one.) Force output to be one entry per line.
136
137
138       Specifying  more  than  one  of  the options in the following mutually-
139       exclusive pairs shall not be considered an error: -C and -l (ell),   -m
140       and  -l (ell), -x and -l (ell),  -C and -1 (one), -H and -L, -c and -u.
141       The last option specified in each pair shall determine the output  for‐
142       mat.
143

OPERANDS

145       The following operand shall be supported:
146
147       file   A pathname of a file to be written. If the file specified is not
148              found, a diagnostic message shall be output on standard error.
149
150

STDIN

152       Not used.
153

INPUT FILES

155       None.
156

ENVIRONMENT VARIABLES

158       The following environment variables shall affect the execution of ls:
159
160       COLUMNS
161              Determine the user's preferred column position width for writing
162              multiple  text-column output. If this variable contains a string
163              representing a decimal integer, the ls utility  shall  calculate
164              how  many  pathname  text columns to write (see -C) based on the
165              width provided. If COLUMNS is not set or invalid, an implementa‐
166              tion-defined  number of column positions shall be assumed, based
167              on the implementation's knowledge of the output device. The col‐
168              umn width chosen to write the names of files in any given direc‐
169              tory shall be constant. Filenames shall not be truncated to  fit
170              into the multiple text-column output.
171
172       LANG   Provide  a  default value for the internationalization variables
173              that are unset or null. (See  the  Base  Definitions  volume  of
174              IEEE Std 1003.1-2001,  Section  8.2,  Internationalization Vari‐
175              ables for the precedence of internationalization variables  used
176              to determine the values of locale categories.)
177
178       LC_ALL If  set  to a non-empty string value, override the values of all
179              the other internationalization variables.
180
181       LC_COLLATE
182
183              Determine the locale  for  character  collation  information  in
184              determining the pathname collation sequence.
185
186       LC_CTYPE
187              Determine  the  locale  for  the  interpretation of sequences of
188              bytes of text data as characters (for  example,  single-byte  as
189              opposed to multi-byte characters in arguments) and which charac‐
190              ters are defined as printable (character class print).
191
192       LC_MESSAGES
193              Determine the locale that should be used to  affect  the  format
194              and contents of diagnostic messages written to standard error.
195
196       LC_TIME
197              Determine  the  format  and  contents  for date and time strings
198              written by ls.
199
200       NLSPATH
201              Determine the location of message catalogs for the processing of
202              LC_MESSAGES .
203
204       TZ     Determine  the timezone for date and time strings written by ls.
205              If TZ is unset or null, an unspecified default timezone shall be
206              used.
207
208

ASYNCHRONOUS EVENTS

210       Default.
211

STDOUT

213       The default format shall be to list one entry per line to standard out‐
214       put; the exceptions are to terminals or when one of the -C,   -m, or -x
215       options  is  specified.  If  the output is to a terminal, the format is
216       implementation-defined.
217
218       When -m is specified, the format used shall be:
219
220
221              "%s, %s, ...\n", <filename1>, <filename2>
222
223       where the largest number of filenames shall be written without  exceed‐
224       ing the length of the line.
225
226       If  the  -i  option  is  specified,  the file's file serial number (see
227       <sys/stat.h>) shall be written in the following format before any other
228       output for the corresponding entry:
229
230
231              %u ", <file serial number>
232
233       If  the  -l  option  is specified without -L, the following information
234       shall be written:
235
236
237              "%s %u %s %s %u %s %s\n", <file mode>, <number of links>,
238                  <owner name>, <group name>, <number of bytes in the file>,
239                  <date and time>, <pathname>
240
241       If the file is a symbolic link, this information  shall  be  about  the
242       link itself and the <pathname> field shall be of the form:
243
244
245              "%s -> %s", <pathname of link>, <contents of link>
246
247       If  both  -l  and  -L are specified, the following information shall be
248       written:
249
250
251              "%s %u %s %s %u %s %s\n", <file mode>, <number of links>,
252                  <owner name>, <group name>, <number of bytes in the file>,
253                  <date and time>, <pathname of link>
254
255       where all fields except <pathname  of  link>  shall  be  for  the  file
256       resolved from the symbolic link.
257
258       The  -g, -n, and -o options use the same format as -l, but with omitted
259       items and their associated <blank>s. See the OPTIONS section.
260
261       In both the preceding -l forms, if <owner name> or <group name>  cannot
262       be determined,    or if -n is given,  they shall be replaced with their
263       associated numeric values using the format %u .
264
265       The <date and time> field shall contain the appropriate date and  time‐
266       stamp  of  when  the  file  was last modified. In the POSIX locale, the
267       field shall be the equivalent of the output of the following date  com‐
268       mand:
269
270
271              date "+%b %e %H:%M"
272
273       if the file has been modified in the last six months, or:
274
275
276              date "+%b %e %Y"
277
278       (where  two  <space>s  are used between %e and %Y ) if the file has not
279       been modified in the last six months or if the modification date is  in
280       the future, except that, in both cases, the final <newline> produced by
281       date shall not be included and the output shall be as if the date  com‐
282       mand  were  executed  at  the time of the last modification date of the
283       file rather than the current time. When the LC_TIME locale category  is
284       not  set to the POSIX locale, a different format and order of presenta‐
285       tion of this field may be used.
286
287       If the file is a character special or block special file, the  size  of
288       the  file may be replaced with implementation-defined information asso‐
289       ciated with the device in question.
290
291       If the pathname was specified as a file operand, it shall be written as
292       specified.
293
294       The  file  mode  written  under the -l,   -g, -n, and -o  options shall
295       consist of the following format:
296
297
298              "%c%s%s%s%c", <entry type>, <owner permissions>,
299                  <group permissions>, <other permissions>,
300                  <optional alternate access method flag>
301
302       The <optional alternate access method flag> shall be a  single  <space>
303       if there is no alternate or additional access control method associated
304       with the file; otherwise, a printable character shall be used.
305
306       The <entry type> character shall describe the type of file, as follows:
307
308       d      Directory.
309
310       b      Block special file.
311
312       c      Character special file.
313
314       l (ell)
315              Symbolic link.
316
317       p      FIFO.
318
319       -      Regular file.
320
321
322       Implementations may add other characters  to  this  list  to  represent
323       other implementation-defined file types.
324
325       The next three fields shall be three characters each:
326
327       <owner permissions>
328
329              Permissions  for  the file owner class (see the Base Definitions
330              volume of IEEE Std 1003.1-2001, Section 4.4, File Access Permis‐
331              sions).
332
333       <group permissions>
334
335              Permissions for the file group class.
336
337       <other permissions>
338
339              Permissions for the file other class.
340
341
342       Each field shall have three character positions:
343
344        1. If 'r' , the file is readable; if '-' , the file is not readable.
345
346        2. If 'w' , the file is writable; if '-' , the file is not writable.
347
348        3. The first of the following that applies:
349
350       S
351              If  in  <owner permissions>, the file is not executable and set-
352              user-ID mode is set. If in <group permissions>, the file is  not
353              executable and set-group-ID mode is set.
354
355       s
356              If  in <owner permissions>, the file is executable and set-user-
357              ID mode is set. If in  <group permissions>,  the  file  is  exe‐
358              cutable and set-group-ID mode is set.
359
360       T
361              If  in  <other permissions>  and the file is a directory, search
362              permission is not granted to others, and the restricted deletion
363              flag is set.
364
365       t
366              If  in  <other permissions>  and the file is a directory, search
367              permission is granted to others,  and  the  restricted  deletion
368              flag is set.
369
370       x
371              The file is executable or the directory is searchable.
372
373       -
374              None  of  the  attributes  of  'S'  ,  's'  , 'T' , 't' , or 'x'
375              applies.
376
377
378       Implementations may add other characters to this  list  for  the  third
379       character position. Such additions shall, however, be written in lower‐
380       case if the file is executable or searchable, and in uppercase if it is
381       not.
382
383       If  any  of the -l,   -g, -n, -o, or -s options is specified, each list
384       of files within the directory shall be preceded by a status line  indi‐
385       cating the number of file system blocks occupied by files in the direc‐
386       tory in 512-byte units, rounded up  to  the  next  integral  number  of
387       units, if necessary. In the POSIX locale, the format shall be:
388
389
390              "total %u\n", <number of units in the directory>
391
392       If more than one directory, or a combination of non-directory files and
393       directories are written, either as a result of specifying multiple  op‐
394       erands,  or  the -R option, each list of files within a directory shall
395       be preceded by:
396
397
398              "\n%s:\n", <directory name>
399
400       If this string is the first thing to be written,  the  first  <newline>
401       shall  not be written. This output shall precede the number of units in
402       the directory.
403
404       If the -s option is given, each file shall be written with  the  number
405       of  blocks  used  by the file. Along with -C, -1, -m, or -x, the number
406       and a <space> shall precede the filename; with -g, -l, -n, or -o,  they
407       shall precede each line describing a file.
408

STDERR

410       The standard error shall be used only for diagnostic messages.
411

OUTPUT FILES

413       None.
414

EXTENDED DESCRIPTION

416       None.
417

EXIT STATUS

419       The following exit values shall be returned:
420
421        0     Successful completion.
422
423       >0     An error occurred.
424
425

CONSEQUENCES OF ERRORS

427       Default.
428
429       The following sections are informative.
430

APPLICATION USAGE

432       Many implementations use the equal sign ( '=' ) to denote sockets bound
433       to the file system for  the  -F  option.   Similarly,  many  historical
434       implementations  use  the  's' character to denote sockets as the entry
435       type characters for the -l option.
436
437       It is difficult for an application to use every part of the file  modes
438       field of ls -l in a portable manner.  Certain file types and executable
439       bits are not guaranteed to be exactly as shown, as implementations  may
440       have extensions.  Applications can use this field to pass directly to a
441       user printout or prompt, but actions based on its contents should  gen‐
442       erally be deferred, instead, to the test utility.
443
444       The output of ls (with the -l and related options) contains information
445       that logically could be used by utilities such as chmod  and  touch  to
446       restore  files to a known state. However, this information is presented
447       in a format that cannot be used directly by those utilities or be  eas‐
448       ily  translated  into  a  format that can be used. A character has been
449       added to the end of the permissions  string  so  that  applications  at
450       least  have  an  indication that they may be working in an area they do
451       not understand instead of assuming that they can translate the  permis‐
452       sions  string into something that can be used. Future issues or related
453       documents may define one or more specific characters to be  used  based
454       on  different  standard additional or alternative access control mecha‐
455       nisms.
456
457       As with many of the utilities that deal with filenames, the  output  of
458       ls  for  multiple  files  or in one of the long listing formats must be
459       used carefully on systems where filenames can  contain  embedded  white
460       space.  Systems and system administrators should institute policies and
461       user training to limit the use of such filenames.
462
463       The number of disk blocks occupied by the file that it  reports  varies
464       depending  on  underlying  file system type, block size units reported,
465       and the method of calculating the number of blocks. On some file system
466       types,  the  number is the actual number of blocks occupied by the file
467       (counting indirect blocks and ignoring holes in the file); on others it
468       is  calculated  based on the file size (usually making an allowance for
469       indirect blocks, but ignoring holes).
470

EXAMPLES

472       An example of a small directory tree being fully listed with ls -laRF a
473       in the POSIX locale:
474
475
476              total 11
477              drwxr-xr-x   3 hlj      prog          64 Jul  4 12:07 ./
478              drwxrwxrwx   4 hlj      prog        3264 Jul  4 12:09 ../
479              drwxr-xr-x   2 hlj      prog          48 Jul  4 12:07 b/
480              -rwxr--r--   1 hlj      prog         572 Jul  4 12:07 foo*
481
482
483              a/b:
484              total 4
485              drwxr-xr-x   2 hlj      prog          48 Jul  4 12:07 ./
486              drwxr-xr-x   3 hlj      prog          64 Jul  4 12:07 ../
487              -rw-r--r--   1 hlj      prog         700 Jul  4 12:07 bar
488

RATIONALE

490       Some historical implementations of the ls utility show all entries in a
491       directory except dot and dot-dot when a superuser  invokes  ls  without
492       specifying  the -a option. When "normal" users invoke ls without speci‐
493       fying -a, they should not see information about any  files  with  names
494       beginning with a period unless they were named as file operands.
495
496       Implementations are expected to traverse arbitrary depths when process‐
497       ing the -R option. The only limitation on depth should be based on run‐
498       ning  out of physical storage for keeping track of untraversed directo‐
499       ries.
500
501       The -1 (one) option was  historically  found  in  BSD  and  BSD-derived
502       implementations    only.   It   is   required   in   this   volume   of
503       IEEE Std 1003.1-2001 so that conforming applications might ensure  that
504       output is one entry per line, even if the output is to a terminal.
505
506       Generally,  this  volume  of  IEEE Std 1003.1-2001 is silent about what
507       happens when options are given multiple times. In the cases of -C,  -l,
508       and  -1,  however,  it  does  specify  the results of these overlapping
509       options. Since ls is one of the most aliased commands, it is  important
510       that  the implementation perform intuitively. For example, if the alias
511       were:
512
513
514              alias ls="ls -C"
515
516       and the user typed ls -1, single-text-column output should result,  not
517       an error.
518
519       The  BSD  ls provides a -A option (like -a, but dot and dot-dot are not
520       written out). The small difference  from  -a  did  not  seem  important
521       enough to require both.
522
523       Implementations may make -q the default for terminals to prevent trojan
524       horse attacks on terminals with special escape sequences. This  is  not
525       required because:
526
527        * Some  control  characters may be useful on some terminals; for exam‐
528          ple, a system might write them as "\001" or "^A" .
529
530        * Special behavior for  terminals  is  not  relevant  to  applications
531          portability.
532
533       An  early  proposal specified that the optional alternate access method
534       flag had to be '+' if there was an alternate access method used on  the
535       file  or  <space>  if  there was not. This was changed to be <space> if
536       there is not and a single printable character if  there  is.  This  was
537       done for three reasons:
538
539        1. There  are  historical  implementations using characters other than
540           '+' .
541
542        2. There are implementations that vary this  character  used  in  that
543           position to distinguish between various alternate access methods in
544           use.
545
546        3. The standard developers did not want to preclude future  specifica‐
547           tions  that  might  need  a  way to specify more than one alternate
548           access method.
549
550       Nonetheless, implementations providing a single alternate access method
551       are encouraged to use '+' .
552
553       In  an  early  proposal, the units used to specify the number of blocks
554       occupied by files in a directory in an ls -l listing  were  implementa‐
555       tion-defined.  This  was  because  BSD  systems  have historically used
556       1024-byte units and System V systems have  historically  used  512-byte
557       units.  It was pointed out by BSD developers that their system has used
558       512-byte units in some places and  1024-byte  units  in  other  places.
559       (System  V  has  consistently  used  512.)   Therefore,  this volume of
560       IEEE Std 1003.1-2001 usually specifies 512. Future releases of BSD  are
561       expected  to  consistently provide 512 bytes as a default with a way of
562       specifying 1024-byte units where appropriate.
563
564       The <date and time> field in the -l format is specified  only  for  the
565       POSIX  locale.  As noted, the format can be different in other locales.
566       No  mechanism  for  defining  this  is  present  in  this   volume   of
567       IEEE Std 1003.1-2001, as the appropriate vehicle is a messaging system;
568       that is, the format should be specified as a "message".
569

FUTURE DIRECTIONS

571       The -s uses implementation-defined units and cannot be  used  portably;
572       it may be withdrawn in a future version.
573

SEE ALSO

575       chmod()  , find , the System Interfaces volume of IEEE Std 1003.1-2001,
576       stat(),  the   Base   Definitions   volume   of   IEEE Std 1003.1-2001,
577       <sys/stat.h>
578
580       Portions  of  this text are reprinted and reproduced in electronic form
581       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
582       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
583       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
584       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
585       event of any discrepancy between this version and the original IEEE and
586       The  Open Group Standard, the original IEEE and The Open Group Standard
587       is the referee document. The original Standard can be  obtained  online
588       at http://www.opengroup.org/unix/online.html .
589
590
591
592IEEE/The Open Group                  2003                                LS(P)
Impressum