ls is used to obtain detailed information on files and directories. The type, scope and output format of the displayed information can be specified by setting various options.
Syntax
ls
[ option]...[ file]... |
No argument specified ls lists the names of files and directories in the current working directory. The output is sorted in alphabetical order. No option specified file is a directory: file is a file:
Lists all file names, including those that begin with a dot.
Non-printing characters in file names are represented in the octal notation \ddd, where ddd is the octal value of the character (see Tables and directories, EBCDIC character set).
Together with option -l Together with option -t:
Multi-column output with entries sorted down the columns in alphabetical order. The default is one entry per line of output. ls uses the environment variable COLUMNS to determine the number of character positions per line. If this variable is not set, the value of the environment variable TERM is checked in the terminfo database in order to determine the number of columns. If this information cannot be obtained, 80 characters per line are assumed.
If file is a directory, ls lists its name (not its contents). This option is often used together with -l in order to obtain information on the status of the directory. If file is omitted, ls outputs a period for the current directory.
Forces each argument to be interpreted as a directory and lists the entries of each directory in the order in which they appear. If no argument is specified, the entries in the current directory are listed. This option turns on the -a option and turns off options -l, -t, -F, -s and -r.
Puts a slash (/) after each file name if the file is a directory, an asterisk (*) if the file is declared as an executable, a commercial at symbol (@) if the file is a symbolic link, a vertical bar
Has the same effect as -l, except that the owner is not printed.
Prints the unique identification number (inode number) for each file in the first column of the report.
A list of detailed information is provided in long format for each file. This information is displayed as shown below: -rwxrwxrwx n name gruppe nnnn Mon nn nn:nn datei || | | | | | | | | || | | | | | | | Dateiname || | | | | | | Uhrzeit || | | | | | Tag || | | | | Monat || | | | Größe in Byte || | | Gruppenname || | Benutzerkennung des Eigentümers || Anzahl der Verweise |Zugriffsrecht Identifikation Identification
Access permissions 3 sets of 3 characters each provide information on the permissions of
Each set uses the following codes: Position 1:
Position 2:
Position 3:
If the s bit (set-user-ID mode) is set for the owner or the group and the corresponding x bit (execute permission) is also set, the x will be replaced by an s. The s bit cannot be set without the corresponding x bit. In the case of group permissions, an S may occupy the position of the x bit if the l bit is set for the file, i.e. if mandatory locking has been enabled for the file. Neither the x bit nor the s bit can be set for the group in this case. For Number of links Login of owner Group name Size in bytes Month, day, time File name In the case of directories, the size of the entire directory is displayed in addition to the individual file sizes. This size is specified in 512-byte blocks (see Example 4). If the file or directory is a symbolic link, the file name is printed followed by an arrow ’->’ and the pathname of the referenced file. Note that in a Remote File Sharing environment, you may not always have the permissions indicated by the output of the ls -l command.
With symbolic links, the link name is listed rather than the name of the original file or directory. Example
Lists files across the page (stream output format), separated by commas. ls uses an environment variable, COLUMNS, to determine the number of character positions per line. If this variable is not set, the value of the environment variable TERM is checked in the terminfo database in order to determine the number of columns. If this information cannot be obtained, 80 columns are assumed per line.
Same effect as -l, except that the user ID and the group ID are displayed instead of the login and group names.
Same effect as -l, except that the group is not displayed.
Puts a slash (/) after each file name if the file is a directory.
Non-printing characters in file names are represented by question marks.
Reverses the sorting order.
Prints the size of each file in column 1 (in 512-byte blocks) in addition to the file names.
Sorts by time last modified instead of by file name (latest first).
Together with option -t Together with option -l
Multi-column output with entries sorted across instead of down the page. ls uses the environment variable, COLUMNS, to determine the number of character positions per line. If this variable is not set, the value of the environment variable TERM is checked in the terminfo database in order to determine the number of columns. If this information cannot be obtained, 80 characters per line are assumed.
Prints only one entry per line of output.
Name of the file or directory for which you want information to be listed. You can also name more than one file or directory. file not specified: |
File
/etc/group Contains all the groups that have been set up. |
Variable
COLUMNS Determine the user’s preferred column position width for writing multiple text-column output. If this variable contains a string representing a decimal integer, the ls utility calculates how many pathname text columns to write (see -C) based on the width provided. The column width chosen to write the names of files in any given directory will be constant. Filenames will not be truncated to fit into multiple text-column output. TZ Determine the timezone for date and time strings written by ls. |
Locale
The following environment variables affect the execution of ls: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the collating sequence of the output from ls. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). It determines which characters are defined as non-printing characters in conjunction with the -q option. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example 1
Listing the contents of the current directory in long format.
|
Example 2
Multi-column output of the current directory using a line width of 80 columns per line. (This output form is also the default for terminal output).
|
Example 3
Multi-column output after defining the line width as 40 columns per line.
|
Example 4
Listing the current directory in long format (option -l), marking directories (option -p) and including all files that begin with a period (option -a).
|
Example 5
List all files and directories (and their contents). Each directory name is followed by a colon.
|
See also
chmod, find, ln |