Displays the contents of a directory.
ls [ -1 ] [ -A ] [ -C ] [ -F ] [-H | -L ] [ -N ] [ -R ] [ -X] [ -a ] [ -b ] [ -c ] [ -d ] [ -e ] [ -f ] [ -g ] [ -i ] [ -l ] [ -m ] [ -n ] [ -o ] [ -p ] [ -q ] [ -r ] [ -s ] [ -t ] [ -u ] [ -U ] [ -x ] [ File ... ]
ls -f [ -C ] [ -d ] [ -i ] [ -m ] [ -s ] [ -X] [ -x ] [ -1 ] [ -U ] [ Directory ... ]
The ls command writes to standard output the contents of each specified Directory parameter or the name of each specified File parameter, along with any other information you ask for with the flags. If you do not specify a File or Directory parameter, the ls command displays the contents of the current directory.
Specifying more than one of the options in the mutually exclusive pairs is not considered an error. The last option specified in each pair determines the output format.
By default, the ls command displays all information in alphabetic order by file name. The collating sequence is determined by the LANG or LC_COLLATE environment variable.
When the ls command displays the contents of a directory, it does not show entries for files whose names begin with a . (dot) unless you use the -a or -A flag. If the command is executed by root, it uses the -A flag by default.
There are three main ways to format the output:
To determine the number of character positions in the output line, the ls command uses the COLUMNS environment variable. If this variable is not set, the command gets the current column value of the display. If the ls command cannot determine the number of character positions by either of these methods, it uses a default value of 80.
E | Indicates a file has extended attributes (EA) information. The EA of a file is displayed by using the getea command. |
- | Indicates a file does not have extended attributes information. |
The mode displayed with the -e and -l flags is interpreted as follows:
d | The entry is a directory. |
b | The entry is a block special file. |
c | The entry is a character special file. |
l | The entry is a symbolic link, and either the -N flag was specified or the symbolic link did not point to an existing file. |
p | The entry is a first-in,first-out (FIFO) special file. |
s | The entry is a local socket. |
- | The entry is an ordinary file. |
The next nine characters are divided into three sets of three characters each. The first set of three characters show the owner's permission. The next set of three characters show the permission of the other users in the group. The last set of three characters shows the permission of anyone else with access to the file. The three characters in each set indicate, respectively, read, write, and execute permission of the file. Execute permission of a directory lets you search a directory for a specified file.
Permissions are indicated as follows:
r | Read |
w | Write (edit) |
x | Execute (search) |
- | Corresponding permission not granted |
The group-execute permission character is s if the file has set-group-ID mode. The user-execute permission character is s if the file has set-user-ID mode. The last character of the mode (usually x or -) is T if the 01000 (octal) bit of the mode is set (see the chmod command for the meaning of this mode). The indications of set-ID and 01000 bit of the mode are capitalized (S and T, respectively) if the corresponding execute permission is not set. The mode t indicates that the sticky bit is on for the file or the directory.
The mode displayed with the -e flag is the same as with the -l flag, except for the addition of an 11th character interpreted as follows:
+ | Indicates a file has extended security information. For example, the file may have extended ACL, TCB, or TP attributes in the mode. |
- | Indicates a file does not have extended security information. |
When the size of the files in a directory are listed, the ls command displays a total count of blocks, including indirect blocks.
This command returns the following exit values:
0 | All files were written successfully. |
>0 | An error occurred. |
ls -aThis lists all files, including . (dot), .. (dot-dot), and other files with names beginning with a dot.
ls -l chap1 .profileThis displays a long listing with detailed information about chap1 and .profile.
ls -d -l .manual manual/chap1This displays a long listing for the directories . and manual, and for the file manual/chap1. Without the -d flag, this would list the files in the . and manual directories instead of the detailed information about the directories themselves.
ls -l -tThis displays a long listing of the files that were modified most recently, followed by the older files.
ls -lX .profileThis displays a long listing with detailed information about .profile.
ls -UExample output:
-rwSr-x---+ 1 root system 28 Apr 29 03:23 only_aixc -rwSr-x---E 1 root system 4 Apr 29 03:23 only_aixc_ea -rw-r--r--E 1 root system 4 Apr 29 03:23 only_ea ----------+ 1 root system 265 Apr 29 03:23 only_nfs4 ----------E 1 root system 64 Apr 29 03:23 only_nfs4_ea -rw-r--r--- 1 root system 4 Apr 29 03:23 only_regular
/usr/bin/ls | Contains the ls command. |
/etc/passwd | Contains user IDs. |
/etc/group | Contains group IDs. |
/usr/share/lib/terminfo/* | Contains terminal information. |