[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter describes the ls
command and its variants dir
and vdir
, which list information about files.
5.1 ls
: List directory contentsList directory contents. 5.2 dir
: Briefly list directory contentsBriefly ls. 5.3 vdir
: Verbosely list directory contentsVerbosely ls. 5.4 dircolors
: Color setup forls
Color setup for ls, etc.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 arguments are specified, ls
lists the contents of the
current directory.
By default, the output is sorted alphabetically. 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.
The `-g' option is accepted but ignored, for compatibility with Unix. Also see 2. Common options.
5.1.1 Which files are listed 5.1.2 What information is listed 5.1.3 Sorting the output 5.1.4 More details about version sort 5.1.5 General output formatting 5.1.6 Formatting the file names
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
$ ls --ignore='.??*' --ignore='.[^.]' --ignore='#*' |
The first option ignores names of length 3 or more that start with `.', the second ignores all two-character names that start with `.' except `..', and the third ignores names that start with `#'.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options affect the information that ls
displays. By
default, only file names are shown.
//DIRED// beg1 end1 beg2 end2 ... |
The begN and endN are unsigned integers that record the byte position of the beginning and end of each file name in the output. This makes it easy for Emacs to find the names, even when they contain unusual characters such as space or newline, without fancy searching.
If directories are being listed recursively (-R
), output a similar
line after each subdirectory:
//SUBDIRED// format beg1 end1 ... |
Finally, output a line of the form:
//DIRED-OPTIONS// --quoting-style=word |
ls
, so we
provide this option for compatibility.)
Warning: the meaning of `-H' will change in the future to conform to POSIX. Use `--si' for the old meaning.
make
that
rely on file times.
For each directory that is listed, preface the files with a line `total blocks', where blocks is the total disk allocation for all files in that directory. The block size currently defaults to 1024 bytes, but this can be overridden (see section 2.2 Block size). The blocks computed counts each hard link separately; this is arguably a deficiency.
The permissions listed are similar to symbolic mode specifications
(see section 3.2 Symbolic Modes). But ls
combines multiple bits into the
third character of each set of permissions as follows:
Following the permission bits is a single character that specifies whether an alternate access method applies to the file. When that character is a space, there is no alternate access method. When it is a printing character (e.g., `+'), then there is such a method.
ls
.
Normally the disk allocation is printed in units of 1024 bytes, but this can be overridden (see section 2.2 Block size).
For files that are NFS-mounted from an HP-UX system to a BSD system,
this option reports sizes that are half the correct values. On HP-UX
systems, it reports sizes that are twice the correct values for files
that are NFS-mounted from BSD systems. This is due to a flaw in HP-UX;
it also affects the HP-UX ls
program.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options affect the appearance of the overall output.
ls
when standard
output is not a terminal.
ls
if standard output is a terminal. It is always the default
for the dir
and d
programs.
GNU ls
uses variable width columns to display as many files as
possible in the fewest lines.
more
or
less
usually produces unreadable results. However, using
more -f
does seem to work.
date
,
but this is planned to change in a future release, partly because modern
file time stamps have more precision. It's not
possible to change the format, but you can extract out the date string with
cut
and then pass the result to date -d
. See section `date invocation' in Shell utilities.
This is most useful because the time output includes the seconds. (Unix filesystems store file timestamps only to the nearest second, so this option shows all the information there is.) For example, this can help when you have a Makefile that is not regenerating files properly.
ls
uses tabs where possible in the output, for efficiency. If
cols is zero, do not use tabs at all.
COLUMNS
is used if it is set; otherwise the default
is 80.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These options change how file names themselves are printed.
ls
.
You can specify the default value of the `--quoting-style' option
with the environment variable QUOTING_STYLE
. If that environment
variable is not set, the default value is `literal', but this
default may change to `shell' in a future version of this package.
ls
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dir
: Briefly list directory contents
dir
(also installed as d
) is equivalent to ls -C
-b
; that is, by default files are listed in columns, sorted vertically,
and special characters are represented by backslash escape sequences.
See section ls
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
vdir
: Verbosely list directory contents
vdir
(also installed as v
) is equivalent to ls -l
-b
; that is, by default files are listed in long format and special
characters are represented by backslash escape sequences.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dircolors
: Color setup for ls
dircolors
outputs a sequence of shell commands to set up the
terminal for color output from ls
(and dir
, etc.).
Typical usage:
eval `dircolors [option]... [file]` |
If file is specified, dircolors
reads it to determine which
colors to use for which file types and extensions. Otherwise, a
precompiled database is used. For details on the format of these files,
run `dircolors --print-database'.
The output is a shell command to set the LS_COLORS
environment
variable. You can specify the shell syntax to use on the command line,
or dircolors
will guess it from the value of the SHELL
environment variable.
The program accepts the following options. Also see 2. Common options.
SHELL
environment variable is set and does not end with `csh' or
`tcsh'.
SHELL
ends with
csh
or tcsh
.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |