ls: List directory contents
The ls program lists information about files (of any type, including
directories). Options and file arguments can be intermixed
arbitrarily, as usual.
For non-option command-line arguments that are directories, by
default ls lists the contents of directories, not recursively, and
omitting files with names beginning with .. For other non-option
arguments, by default ls lists just the file name. If no non-option
argument is specified, ls operates on the current directory, acting
as if it had been invoked with a single argument of ..
By default, the output is sorted alphabetically, according to the locale settings in effect. (1) If standard output is a terminal, the output is in columns (sorted vertically) and control characters are output as question marks; otherwise, the output is listed one per line and control characters are output as-is.
Because ls is such a fundamental program, it has accumulated many
options over the years. They are described in the subsections below;
within each section, options are listed alphabetically (ignoring case).
The division of options into the subsections is not absolute, since some
options affect more than one aspect of ls''s operation.
An exit status of zero indicates success, and a nonzero value indicates failure.
Also see *Note Common options
(1) If you use a non-POSIX locale (e.g., by setting LC_ALL to
en_US, then ls may produce output that is sorted differently than
you're accustomed to. In that case, set the LC_ALL environment
variable to C.
10.1.1 Which files are listed
These options determine which files ls lists information for. By
default, any files and the contents of any directories on the command
line are shown.
-a |
10.1.2 What information is listed
These options affect the information that ls displays. By default,
only file names are shown.
--author |
These options change the order in which ls sorts the information it
outputs. By default, sorting is done by character code (e.g., ASCII
order).
-c |
10.1.4 More details about version sort
The version sort takes into account the fact that file names frequently
include indices or version numbers. Standard sorting functions usually
do not produce the ordering that people expect because comparisons are
made on a character-by-character basis. The version sort addresses
this problem, and is especially useful when browsing directories that
contain many files with indices/version numbers in their names:
> ls -1 > ls -1v
foo.zml-1.gz foo.zml-1.gz
foo.zml-100.gz foo.zml-2.gz
foo.zml-12.gz foo.zml-6.gz
foo.zml-13.gz foo.zml-12.gz
foo.zml-2.gz foo.zml-13.gz
foo.zml-25.gz foo.zml-25.gz
foo.zml-6.gz foo.zml-100.gz
Note also that numeric parts with leading zeroes are considered as
fractional one:
> ls -1 > ls -1v
abc-1.007.tgz abc-1.007.tgz
abc-1.012b.tgz abc-1.01a.tgz
abc-1.01a.tgz abc-1.012b.tgz
This functionality is implemented using the strverscmp function.
*Note String/Array Comparison: (libc)String/Array Comparison. One
result of that implementation decision is that ls -v does not use the
locale category, LC_COLLATE. As a result, non-numeric prefixes are
sorted as if LC_COLLATE were set to C.
10.1.5 General output formatting
These options affect the appearance of the overall output.
-1 |
2002-03-30 23:45. However, the default
POSIX locale uses a date like Mar 30 2002 for non-recent timestamps,
and a date-without-year and time like Mar 30 23:45 for recent
timestamps.
A timestamp is considered to be "recent" if it is less than six
months old, and is not dated in the future. If a timestamp dated today
is not listed in recent form, the timestamp is in the future, which
means you probably have clock skew problems which may break programs
like make that rely on file timestamps.
The following option changes how file timestamps are printed.
|
10.1.7 Formatting the file names
These options change how file names themselves are printed.
-b |
copyright 2006-2007 phpman.info | contact: admin at phpman.info