You can list the files in a directory. The List command (ls) lets you view the files and subdirectories that exist in your working directory. You can also list a file or the contents of a specific directory by name. For example, you can list the contents of a subdirectory within your working directory without switching to that directory.
You can use different command options with the List command to display directory contents in different ways. Command options are predefined modifications that let you add more specific instructions to the command. For example, you can use the Long option (-l) to see details, such as the file size, ownership, and permissions. You can use the All option (-a) to list all files in a directory, including hidden files. For more information about command options, see "Understanding Linux commands."
The following table lists some of the List command options. For a complete list of options, see the Manual page for the List command by typing man ls, at the command line.
Option... |
Lists... |
-a |
all files including hidden files. For information about hidden files, see "Navigating the file system." |
-l |
files in long format, including information such as, permissions, owner, file size, and modification time |
-p |
files and directories and adds a slash (/) to mark directories |
-r |
files in reverse order (by name or time) |
-X |
files according to file extension |
-F |
filenames by marking directories using a slash (/), executable files using an asterisk (*), symbolic links using an at symbol (@), FIFOs using a pipe (|), and sockets using an equal sign (=) |
To list directory contents
1. At the command line, type,
ls [options]
2. Press ENTER.
To list a specific directory or file
1. At the command line, type,
ls [options][<directory>... <filename>...]
2. Press ENTER.
Notes
Do not include the brackets in the command line text. For information about notation conventions for commands, see "Using notation conventions for Linux commands."
The ellipsis indicates that you can list multiple directories or files simultaneously by typing each directory name or filename; for example, ls [options] <dir1> <dir2> <dir3>.
Remember to include a hyphen (-) before the command option. You can specify more than one command option; for example, -laF.
If your working directory does not contain the directory or filename you want to list, use the absolute path name to locate the directory or file. For information about absolute path names, see "Navigating the file system."