ls

Display information about one or more files.

Format

   ls [options] file-list

Summary

The ls utility displays information about one or more files. It lists the information alphabetically by filename unless you use an option to change the order.

Arguments

When you do not use an argument, ls displays the names of the files in the working directory. If you do not use the -a option, ls does not list files whose filenames begin with ..

The file-list contains one or more pathnames of files. You can use the pathname of any ordinary, directory, or device file. These pathnames can include ambiguous file references.

When you specify a directory, ls displays the contents of the directory. The ls utility displays the name of the directory only when it is needed to avoid ambiguity (that is, when ls is displaying the contents of more than one directory, it displays the names of the directories to indicate which files you can find in which directory). If you specify an ordinary file, ls displays information about just that file.

Options

The options determine the type of information ls displays, how it displays it, and the order in which it is displayed.

When you do not use an option, ls displays a short listing, containing only the names of files.

-a all entries Without a file-list (no arguments on the command line), this option displays information about all the files in the working directory, including invisible files (those with filenames that begin with a period). When you do not use this option, ls does not list information about invisible files, unless you list the name of an invisible file in file-list.

In a similar manner, when you use this option with a file-list that includes an appropriate ambiguous file reference, ls displays information about invisible files. (The * ambiguous file reference does not match a leading period in a filename.)
-d directory This option displays the names of directories without displaying their contents. When you give this option without an argument, ls displays information about the working directory. This option displays ordinary files normally.
-l long This option displays several columns of information about each file.
-L symbolic link When you use this option, ls lists information about the file referenced by each symbolic link rather than information about the link itself.

Notes

The -l option displays the seven columns shown in the figure to the right. The first column, which contains 10 characters, is divided as follows. The first character describes the type of file:

First Character Type of File
- ordinary
d directory
l symbolic link

The next nine characters represent all the access permissions associated with the file. These nine characters are divided into three sets of three characters each.

The first three character's represent the owner's access permissions. If the owner has read access permission, an r appears in the first character position. If the owner is not permitted to read the file, a hyphen appears in this position. The next two positions represent the owner's write and execute access permissions. A w appears in the second position if the owner is permitted to write to the file, and an x appears in the third position if the owner is permitted to execute the file.

In a similar manner, the second and third sets of three characters represent the access permissions of the owner's group and other users.

The second column indicates the number of hard links to the file.

The third and fourth columns display the name of the owner of the file and the name of the group the file belongs to.

The fifth column indicates the size of the file in bytes. In the case of a directory, this number is the size of the actual directory file, not the size of the files that are entries within the directory.

The last two columns display the date and time the file was last modified, and the filename.

Filename Colors

The departmental Unix servers, turing and hopper, display certain types of filenames in colors other than the default white:

Examples

All of the following examples assume that the user does not change to another working directory.

The first command line shows the default behavior of the ls utility. You see an alphabetical list of the names of the files in the working directory.

z123456@turing:~$ ls
bin  csci241  prog1.cpp  public_html  text

Next, the -l (long) option displays a long list. The files are still in alphabetical order.

z123456@turing:~$ ls -l
total 20
drwxr-xr-x 2 z123456 csci 4096 2010-08-21 10:58 bin
drwxr-xr-x 9 z123456 csci 4096 2010-07-01 12:19 csci241
-rw-r--r-- 1 z123456 csci  111 2010-12-20 20:59 prog1.cpp
lrwxrwxrwx 1 root    root   29 2008-10-23 16:04 public_html -> /home/www/z123456/public_html
-rw-r--r-- 1 z123456 csci   11 2010-12-27 11:18 text

The -a (all) option lists all files, including invisible ones.

z123456@turing:~$ ls -a
.   .bash_history  bin      prog1.cpp    text
..  .bashrc        csci241  public_html

Combining the -a and -l options displays a long listing of all the files, including invisible files, in the working directory. This list is still in alphabetical order.

z123456@turing:~$ ls -al
total 68
drwxr-xr-x  12 z123456 csci  4096 2010-12-27 11:18 .
drwxr-xr-x 891 root    root 20480 2010-10-06 13:24 ..
-rw-------   1 z123456 csci  7842 2010-12-27 10:52 .bash_history
-rw-r--r--   1 z123456 csci    37 2010-07-27 10:54 .bashrc
drwxr-xr-x   2 z123456 csci  4096 2010-08-21 10:58 bin
drwxr-xr-x   9 z123456 csci  4096 2010-07-01 12:19 csci241
-rw-r--r--   1 z123456 csci   111 2010-12-20 20:59 prog1.cpp
lrwxrwxrwx   1 root    root    29 2008-10-23 16:04 public_html -> /home/www/z123456/public_html
-rw-r--r--   1 z123456 csci    11 2010-12-27 11:18 text

The next example shows ls with a directory filename as an argument. The ls utility lists the contents of the directory in alphabetical order.

z123456@turing:~$ ls bin
mailprog.241

To display information about the directory itself, use the -d (directory) option. This option causes ls to list information only about the directory.

z123456@turing:~$ ls -dl bin
drwxr-xr-x   2 z123456 csci  4096 2010-08-21 10:58 bin