Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   ls.1p    ( 1 )

список содержимого каталога (list directory contents)

Обоснование (Rationale)

Some historical implementations of the ls utility show all
       entries in a directory except dot and dot-dot when a superuser
       invokes ls without specifying the -a option. When ``normal''
       users invoke ls without specifying -a, they should not see
       information about any files with names beginning with a <period>
       unless they were named as file operands.

Implementations are expected to traverse arbitrary depths when processing the -R option. The only limitation on depth should be based on running out of physical storage for keeping track of untraversed directories.

The -1 (one) option was historically found in BSD and BSD-derived implementations only. It is required in this volume of POSIX.1‐2017 so that conforming applications might ensure that output is one entry per line, even if the output is to a terminal.

The -S option was added in Issue 7, but had been provided by several implementations for many years. The description given in the standard documents historic practice, but does not match much of the documentation that described its behavior. Historical documentation typically described it as something like:

-S Sort by size (largest size first) instead of by name. Special character devices (listed last) are sorted by name.

even though the file type was never considered when sorting the output. Character special files do typically sort close to the end of the list because their file size on most implementations is zero. But they are sorted alphabetically with any other files that happen to have the same file size (zero), not sorted separately and added to the end.

This volume of POSIX.1‐2017 is frequently silent about what happens when mutually-exclusive options are specified. Except for -R, -d, and -f, the ls utility is required to accept multiple options from each mutually-exclusive option set without treating them as errors and to use the behavior specified by the last option given in each mutually-exclusive set. Since ls is one of the most aliased commands, it is important that the implementation perform intuitively. For example, if the alias were:

alias ls="ls -C"

and the user typed ls -1 (one), single-text-column output should result, not an error.

The -g, -l (ell), -n, and -o options are not mutually-exclusive options. They all enable long format output. They work together to determine whether the file's owner is written (no if -g is present), file's group is written (no if -o is present), and if the file's group or owner is written whether it is written as the name (default) or a string representation of the UID or GID number (if -n is present). The -C, -m, -x, and -1 (one) are mutually-exclusive options and the first three of these disable long format output. The -1 (one) option does not directly change whether or not long format output is enabled, but by overriding -C, -m, and -x, it can re-enable long format output that had been disabled by one of these options.

Earlier versions of this standard did not describe the BSD -A option (like -a, but dot and dot-dot are not written out). It has been added due to widespread implementation.

Implementations may make -q the default for terminals to prevent trojan horse attacks on terminals with special escape sequences. This is not required because:

* Some control characters may be useful on some terminals; for example, a system might write them as "\001" or "^A".

* Special behavior for terminals is not relevant to applications portability.

An early proposal specified that the <optional alternate access method flag> had to be '+' if there was an alternate access method used on the file or <space> if there was not. This was changed to be <space> if there is not and a single printable character if there is. This was done for three reasons:

1. There are historical implementations using characters other than '+'.

2. There are implementations that vary this character used in that position to distinguish between various alternate access methods in use.

3. The standard developers did not want to preclude future specifications that might need a way to specify more than one alternate access method.

Nonetheless, implementations providing a single alternate access method are encouraged to use '+'.

Earlier versions of this standard did not have the -k option, which meant that the -s option could not be used portably as its block size was implementation-defined, and the units used to specify the number of blocks occupied by files in a directory in an ls -l listing were fixed as 512-byte units. The -k option has been added to provide a way for the -s option to be used portably, and for consistency it also changes the aforementioned units from 512-byte to 1024-byte.

The <date and time> field in the -l format is specified only for the POSIX locale. As noted, the format can be different in other locales. No mechanism for defining this is present in this volume of POSIX.1‐2017, as the appropriate vehicle is a messaging system; that is, the format should be specified as a ``message''.