ls
List directory contents
TLDR
List files one per line
List all files, including hidden files
List files with a trailing symbol to indicate file type (directory/, symbolic_link@, executable*, ...)
List all files in [l]ong format (permissions, ownership, size, and modification date)
List files in [l]ong format with size displayed using human-readable units (KiB, MiB, GiB)
List files in [l]ong format, sorted by [S]ize (descending) recursively
List files in [l]ong format, sorted by [t]ime the file was modified and in reverse order (oldest first)
Only list directories
SYNOPSIS
ls [OPTION]... [FILE]...
PARAMETERS
-a
Do not ignore entries starting with . (dotfiles).
-l
Use a long listing format, showing permissions, number of hard links, owner, group, size, and modification time.
-h
With -l, print sizes in human readable format (e.g., 1K, 234M, 2G).
-R
List subdirectories recursively.
-t
Sort by modification time, newest first.
-r
Reverse order while sorting.
-S
Sort by file size, largest first.
-d
List directory entries themselves, not their contents. Useful for seeing information about the directory itself.
-F
Append an indicator (one of */=@|) to entries.
-i
Print the index number (inode) of each file.
-k
Print sizes in 1K blocks, overriding POSIXLY_CORRECT.
-m
Fill width with a comma separated list of entries.
-n
Like -l but list numeric user and group IDs.
-o
Like -l but do not show group information.
-g
Like -l but do not show owner information.
-Q
Enclose entry names in double quotes.
-s
Print the allocated size of each file, in blocks.
-u
With -t, sort by access time; with -l, show access time.
-X
Sort alphabetically by entry extension.
-1
List one file per line.
DESCRIPTION
The ls command is one of the most fundamental and frequently used commands in Unix-like operating systems. It is used to list the contents of directories. When executed without any arguments, ls displays the names of files and subdirectories in the current working directory.
With various options, ls can provide detailed information about files, such as their permissions, ownership, size, last modification time, and inode number. It can also sort output in different ways, display hidden files, and recursively list the contents of subdirectories. Its primary purpose is to help users navigate and understand the file system structure by showing what's inside a directory.
CAVEATS
The exact behavior and available options of ls can vary slightly between different Unix-like systems (e.g., GNU ls vs. BSD ls).
Output parsing: While ls output is human-readable, parsing it programmatically is generally discouraged due to variability in formatting and potential issues with special characters in filenames. For scripting, find -print0 and xargs -0 or stat are preferred.
INTERPRETING <I>LS -L</I> OUTPUT
The long listing format provided by ls -l offers a wealth of information:
- First character: file type (d for directory, - for regular file, l for symbolic link, etc.)
- Next 9 characters: file permissions (read, write, execute for owner, group, others)
- Number: number of hard links
- First name: owner of the file
- Second name: group owner of the file
- Number: file size in bytes (or human-readable with -h)
- Date/Time: last modification time
- Last field: filename
Files and directories whose names begin with a dot (.) are considered "hidden" by convention. ls does not show them by default. To display them, the -a (all) option must be used, e.g., ls -a.
HISTORY
The ls command dates back to the earliest versions of Unix. It was one of the first utilities available in AT&T Unix, originating from the list command on Multics. Over time, it has evolved from a simple listing tool to a powerful command with numerous options, particularly with the GNU Core Utilities implementation, which added many features not present in traditional Unix versions. Its core functionality, however, has remained consistent: displaying directory contents.