Displays the contents of a directory.
ls [ -1 ] [ -A ] [ -C ] [ -F ] [ -L ] [ -N ] [ -R ] [ -a ] [ -b ] [ -c ] [ -d ] [ -e ] [ -f ] [ -g ] [ -i ] [ -l ] [-m ] [ -n ] [ -o ] [ -p ] [ -q ] [ -r ] [ -s ] [ -t ] [ -u ] [ -x ] [ File ... ]
ls -f [ -C ] [ -d ] [ -i ] [ -m ] [ -s ] [ -x ] [ -1 ] [ 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. The "National Language Support Overview for Programming" in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs contains more details.
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.
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 (normally 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 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.
The access control information (ACL) of a file is displayed by using the aclget command. The value of the TCB and TP attributes are displayed by using the chtcb command. |
- | 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.
-A | Lists all entries except . (dot) and .. (dot-dot). |
-a | Lists all entries in the directory, including the entries that begin with a . (dot). |
-b | Displays nonprintable characters in an octal (\nnn) notation. |
-c | Uses the time of last modification of the i-node for either sorting (when used with the -t flag) or for displaying (when used with the -l flag). This flag must be used with either the -t or -l flag, or both. |
-C | Sorts output vertically in a multicolumn format. This is the default method when output is to a terminal. |
-d | Displays only the information for the directory named. Directories are treated like files, which is helpful when using the -l flag to get the status of a directory. |
-e | Displays the mode (including security information), number of links, owner, group, size (in bytes), time of last modification, and name of each file. If the file is a special file, the size field contains the major and minor device numbers. If the file is a symbolic link, the path name of the linked-to file is printed preceded by a -> (minus, greater than) sign. The attributes of the symbolic link are displayed. |
-f | Lists the name in each slot for each directory specified in the Directory parameter. This flag turns off the -l, -t, -s, and -r flags, and turns on the -a flag. The order of the listing is the order in which entries appear in the directory. |
-F | Puts a / (slash) after each file name if the file is a directory, an * (asterisk) if the file can be executed, an = (equal sign) if the file is a socket, a | (pipe) sign if the file is a FIFO, and an @ for a symbolic link.
Note: Symbolic links are displayed with the trailing -> only if the -N flag is used or if the link points to a nonexistent file. Otherwise, information about the target file is displayed. You can also invoke this option by entering the ls -f command. |
-g | Displays the same information as the -l flag, except the -g flag suppresses display of the owner and symbolic link information. |
-i | Displays the i-node number in the first column of the report for each file. |
-L | Lists the file or directory contents that the link references. This is the default action. Symbolic links are followed. If the -l option is used, the -N option becomes the default, and no symbolic links are followed. When the -l option is used, only the -L option can override the -N default. |
-l | (Lower case L) Displays the mode, number of links, owner, group, size (in bytes), and time of last modification for each file. If the file is a special file, the size field contains the major and minor device numbers.
If the file is a symbolic link, the path name of the linked-to file is printed preceded by a ->. The attributes of the symbolic link are displayed. The -n, -g, and -o flag overrides the -l flag. Notes: |
-m | Uses stream output format (a comma-separated series). |
-n | Displays the same information as the -l flag, except that the -n flag displays the user and the group IDs instead of the user and group names. |
-N | Does not follow symbolic links when determining the status of a file.
Note: If both the -L and -N options are used, the last one will dominate. Also, any time a symbolic link is given that includes a / (slash) as the final character, the link will automatically be followed regardless of any options used. |
-o | Displays the same information as the -l flag, except the -o flag suppresses display of the group and symbolic link information. |
-p | Puts a slash after each file name if that file is a directory. This is useful when you pipe the output of the ls command to the pr command, as follows:
ls -p | pr -5 -t -w80 |
-q | Displays nonprintable characters in file names as a ? (question mark). |
-r | Reverses the order of the sort, giving reverse alphabetic or the oldest first, as appropriate. |
-R | Lists all subdirectories recursively. |
-s | Gives size in kilobytes (including indirect blocks) for each entry. |
-t | Sorts by time of last modification (latest first) instead of by name. |
-u | Uses the time of the last access, instead of the time of the last modification, for either sorting (when used with the -t flag) or for displaying (when used with the -l flag). This flag has no effect if it is not used with either the -t or -l flag, or both. |
-x | Sorts output horizontally in a multicolumn format. |
-1 | Forces output into one-entry-per-line format. This is the default when the output is not directed to a terminal. |
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.
/usr/bin/ls | Contains the ls command. |
/etc/passwd | Contains user IDs. |
/etc/group | Contains group IDs. |
/usr/share/lib/terminfo/* | Contains terminal information. |
The aclget command, chmod command, chtcb command, find command, mkpasswd command, qprt command.
Directory Overview in AIX Version 4.3 System User's Guide: Operating System and Devices describes the structure and characteristics of directories in the file system.
Files and Directories Overview in AIX Version 4.3 System User's Guide: Operating System and Devices.
Files Overview in AIX Version 4.3 System User's Guide: Operating System and Devices describes files, file types, and how to name files.
Linking Files and Directories in AIX Version 4.3 System User's Guide: Operating System and Devices explains the concept of file linking.
Shells Overview in AIX Version 4.3 System User's Guide: Operating System and Devices describes shells, the different types, and how they affect the way commands are interpreted.
File and Directory Access Modes in AIX Version 4.3 System User's Guide: Operating System and Devices introduces file ownership and permissions to access files and directories.
National Language Support Overview for Programming in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs explains collating sequences, equivalence classes, and locale.