ls - List directory contents

Synopsis

ls [-ACFLRSTacdfiloqrstu1] [file ...]

Description

For each operand that names a file of a type other than directory, ls displays its name as well as any requested, associated information. For each operand that names a file of type directory, ls displays the names of files contained within that directory, as well as any requested, associated information.

If no operands are given, the contents of the current directory are displayed. If more than one operand is given, non-directory operands are displayed first; directory and non-directory operands are sorted separately and in lexicographical order.

Options

-A
List all entries except for "." and "..".
-C
Force multi-column output; this is the default when output is to a terminal.
-F
Display a slash (/) immediately after each path name that is a directory, an asterisk (*) after each that is executable, and an at sign (@) after each symbolic link.
-L
If argument is a symbolic link, list the file or directory the link references rather than the link itself.
-R
Recursively list subdirectories.
-S
Display the CCSID attribute for the file, or sort and display files by size. The behavior depends on environment variable QIBM_ZSH_LS_SORT_BY_SIZE.
-T
Display complete time information for the file, including month, day, hour, minute, second, and year when the -l option is also specified.
-a
Include directory entries whose names begin with a dot (.).
-c
Use time when file status was last changed for sorting or printing.
-d
Directories are listed as plain files (not searched recursively) and symbolic links in the argument list are not indirected through.
-f
Output is not sorted.
-i
For each file, print the file's file serial number (inode number).
-l
(Lowercase letter `ell.') List in long format. See Extended Description below for details. If the output is to a terminal, a total sum for all the file sizes is output on a line before the long listing.
-o
Include the file flags in a long (-l) output.
-q
Force printing of non-graphic characters in file names as the question mark (?) character. This is the default when output is to a terminal.
-r
Reverse the order of the sort to get reverse lexicographical order or the oldest entries first.
-s
Display the number of bytes actually allocated for each file, in units of 1024 bytes, where partial units are rounded up to the next integer value.
-t
Sort by time modified (most recently modified first) before sorting the operands by lexicographical order.
-u
Use time of last access, instead of last modification of the file for sorting (-t) or printing (-l).
-1
(The numeric digit one) Force output to be one entry per line. This is the default when output is not to a terminal.

The -1, -C, and -l options all override each other. The last one specified determines the format used.

The -c, and -u options override each other. The last one specified determines the file time used.

By default, ls lists one entry per line to standard output; the exceptions are to terminals or when the -C option is specified.

File information is displayed with one or more blanks separating the information associated with the -i, -s, -l, and -S options.

Extended description

If the -l option is specified, the following long format information is displayed for each file:

  • file mode,
  • number of links,
  • owner name,
  • group name,
  • number of bytes in the file,
  • time the file was last modified, and
  • the path name.

If the file was modified within six months of the current date, the time is displayed as the abbreviated month, day-of-month, hour, and minute. Otherwise the time is displayed as the abbreviated month, day-of-month, and four-digit year.

In addition, for each directory whose contents are displayed, the total number of bytes used by the files in the directory is displayed on a line by itself immediately before the information for the files in the directory.

If the owner or group names are not a known user or group name the numeric identifiers are displayed.

If the file is a character special or block special file, the major and minor device numbers for the file are displayed in the size field. If the file is a symbolic link the pathname of the linked-to file is preceded by "->".

The file mode consists of the entry type, owner permissions, group permissions, and other permissions. The entry type character describes the type of file, as follows:

  • b for a block special file.
  • c for a character special file.
  • d for a directory.
  • l for a symbolic link.
  • p for a pipe.
  • s for a socket.
  • - for a regular file.

The owner permissions, group permissions, and other permissions are each three characters. Each field has three character positions:

  • For the first position, if the value is r, the file is readable. If the value is -, it is not readable.
  • For the second position, if the value is w, the file is writable. If the value is -, it is not writable.
  • For the third position,
    • If the value is S for the owner permissions, the set-user-ID mode is set. If the value is S for the group permissions, the set-group-ID mode is set.
    • If the value is s for the owner permissions, the file is executable and the set-user-ID mode is set. If the value is s for the group permissions, the file is executable and the set-group-ID mode is set.
    • If the value is x, the file is executable or the directory is searchable.
    • If the value is -, the object is not executable or searchable.

Environment variables

ls is affected by the following environment variables:

COLUMNS
If this variable contains a string representing a decimal integer, it is used as the column position width for displaying multiple-text-column output. The ls utility calculates how many path name text columns to display based on the width provided. See the -C option.
QIBM_ZSH_LS_SORT_BY_SIZE
Set this environment variable to control how the ls utility to show the ls -S results. If the value of the variable is '1', ls -S sorts the files by size and display. Otherwise ls -S displays the CCSID attribute for a file. There is no default value.

Exit status

  • 0 on success
  • >0 if an error occurs.
Examples
  1. Display the list of files in the current directory using the long format.
    
    ls -l
    
  2. Display all date and time details for the file "myfile".
    
    ls -lT myfile
    -rwxrwxrwx  1 abbey  0      592 Sep 12 22:47:01 1998 myfile