On Unix-like operating systems, the ls command lists information about files and directories.
This page covers the GNU/Linux version of ls.
Description
ls lists files and directories, and their associated metadata, such as file size, ownership, and modification time. With no options, ls lists the files contained in the current directory, sorting them alphabetically.
- Description
- Syntax
- Information in a “long” listing
- Examples
- Related commands
- Linux commands help
Syntax
ls [option …] [file]…
ls [-a | –all] [-A | –almost-all] [–author] [-b | –escape] [–block-size=size] [-B | –ignore-backups] [-c] [-C] [–color[=when]] [-d | –directory] [-D | –dired] [-f] [-F | –classify] [–file-type] [–format=word] [–full-time] [-g] [–group-directories-first] [-G | –no-group] [-h | –human-readable] [–si] [-H | –dereference-command-line] [–dereference-command-line-symlink-to-dir] [–hide=pattern] [–indicator-style=word] [-i | –inode] [-I | –ignore=pattern] [-k | –kibibytes] [-l] [-L | –dereference] [-m] [-n | –numeric-uid-gid] [-N | –literal] [-o] [-p | –indicator-style=slash] [-q | –hide-control-chars] [–show-control-chars] [-Q | –quote-name] [–quoting-style=word] [-r | –reverse] [-R | –recursive] [-s | –size] [-S] [–sort=word] [–time=word] [–time-style=style] [-t] [-T | –tabsize=cols] [-u] [-U] [-v] [-w | –width=cols] [-x] [-X] [-Z | –context] [-1]
ls [–help | –version]
Options
Size Format
size is an integer and optional unit (example: 10M is 1010241024). Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, … (powers of 1000).
Using color to distinguish file types is disabled both by default and with –color=never. With –color=auto, ls emits color codes only when standard output is connected to a terminal. The LS_COLORS environment variable can change the settings. Use the dircolors command to set it.
Exit Status
Information shown in a “long” listing
To view extended information about files, use the -l option to create a “long” listing. For instance:
ls -l file.txt
…displays something like the following:
-rwxrw-r– 1 hope hopestaff 123 Feb 03 15:36 file.txt
Here’s what each part of this information means:
Examples
ls -l
Lists the total files in the directory and subdirectories, the names of the files in the current directory, their permissions, the number of subdirectories in directories listed, the size of the file, and the date of last modification.
ls -laxo
Lists files with permissions, shows hidden files, displays them in a column format, and suppresses group information.
ls ~
List the contents of your home directory by adding a tilde after the ls command.
ls /
List the contents of your root directory.
ls ../
List the contents of the parent directory.
ls */
List the contents of all subdirectories.
ls -d */
Display a list of directories in the current directory.
ls *.{htm,php,cgi}
List all files containing the file extension .htm, .php, or .cgi
ls -ltr
List files sorted by the time they were last modified in reverse order (most recently modified files last).
ls [aeiou]*
In the above example, only files that begin with a vowel (a, e, i, o, or u).
ls myfile.txt 2>/dev/null
Silences or suppresses any error message if the ls command does not find the file.
Related commands
chmod — Change the permissions of files or directories.df — Report the amount of available disk space on file systems.diff — Identify the differences between two files.du — Report the amount of disk space used by a file or files.file — Determine a file’s type.grep — Search for and output lines that match a specified pattern.stat — Display the status of a file or filesystem.tree — List the contents of a file hierarchy visually in a tree format.
Please also see our explanation of the ./ and ../ directories listed in the listing of files.