← Full reference

ls

List directory contents — permissions, owners, sizes, dates, sorting

ls shows the contents of directories and information about files. Without arguments — the current directory; hidden files (names starting with a dot) aren't shown. The sandbox has GNU coreutils 9.4.

Syntax

ls [options] [file_or_directory…]

If an argument is a directory, ls prints its contents; to see the directory itself, add -d. With several arguments: files first, then each directory as a separate block with a name: header.

Exit code: 0 — all is well, 1 — minor problems (a subdirectory couldn't be opened), 2 — serious ones (an argument doesn't exist).

Long format -l

-rw-r--r--  1 root root  1530 Sep 30 13:10 /etc/passwd
drwxr-xr-x  2 root root  4096 Oct 13 15:20 sub
lrwxrwxrwx  1 root root     5 Oct 13 15:20 lnk -> a.txt
crw-rw-rw-  1 root root  1, 3 Oct 13 15:20 /dev/null
ColumnMeaning
1st charactertype: - file, d directory, l symbolic link, c character device, b block device, p named pipe (FIFO), s socket
rw-r--r--permissions of the owner, group, others. s/S in place of x — SUID/SGID (with x / without), t/T — the sticky bit (as on /tmp: drwxrwxrwt)
+ after the permissionsthe file has an ACL (see getfacl)
a numberthe hard link count; for a directory usually 2 + the number of subdirectories (in container overlayfs it can be just 1)
root rootowner and group (-n — numeric UID/GID)
sizein bytes (-h — in K/M/G). For a directory — the size of the directory entry itself (usually 4096), not its contents. For devices — a "major, minor" number pair
datecontent modification time (mtime). Files younger than six months — Mon DD HH:MM, older — Mon DD YYYY
namefor a link — name -> target

The total N line above the list is how much space the listed files take, in 1 KiB blocks (with -h — in K/M).

Options

What to show

OptionWhat it does
-ashow everything, including hidden files and ./..
-Ashow hidden files, but not . and ..
-dshow the directory itself rather than its contents: ls -ld /etc
-Rwalk subdirectories recursively
-I 'pattern'hide matching names (can be repeated); --hide='pattern' — the same, but -a/-A override it
-Lfor links show information about the target, not the link itself
-Hfollow links only from the command line

Output format

OptionWhat it does
-llong format (the table above)
-hsizes as 1.5K, 234M, 2G (powers of 1024); --si — powers of 1000
--block-size=Mshow sizes in the given units (K, M, G), rounding up
-nlike -l, but numeric UID and GID instead of names
-g / -olike -l, but without the owner / without the group
-iinode number before the name
-sdisk space used in blocks (with -h — in K/M)
-1one name per line
-mcomma-separated on one line
-Fa type indicator after the name: / directory, * executable, @ link, | FIFO, = socket
-ponly / after directories
--full-timethe full date with seconds, nanoseconds and time zone
--time-style=long-isodate 2026-10-13 15:20; full-iso, iso, +FORMAT (as in date): --time-style=+%F
-Qnames in double quotes; -N — no quotes at all
--color=autocolor by type, only if output goes to a terminal; always — always, never — never
--group-directories-firstdirectories at the top of the list

Sorting

By default — by name, according to the locale.

OptionHow it sorts
-tby modification time (mtime), newest first
-Sby size, largest first
-Xby extension
-v"naturally": b2 before b10
-Udon't sort (directory order) — faster on huge directories
-rreverse any order: -ltr — oldest at the top, newest at the bottom
--sort=WORDsize, time, version, extension, width, none
-uwith -lt: sort by and show access time (atime)
-cwith -lt: by metadata change time (ctime)
--time=birthuse the file creation time (if the filesystem stores it)

Examples

# detailed, with hidden files and human-readable sizes
ls -lah /etc/ssh

# permissions of the directory itself, not its contents
ls -ld /var/log

# newest files at the bottom of the list
ls -ltr /var/log

# the five largest files in a directory
ls -lS /usr/bin | head -6

# only subdirectories of the current directory
ls -d */

# inode numbers: hard links share them
ls -li

# date in ISO format — convenient for comparisons and scripts
ls -l --time-style=long-iso /etc/hostname

# numeric UID/GID — visible when the owner isn't in /etc/passwd
ls -ln /srv

Pitfalls

  • Don't parse ls output in scripts. Names with spaces and newlines break for f in $(ls), and the date format depends on the file's age and the locale. Use the glob for f in * or find … -print0.
  • Output to a terminal and to a pipeline differs. In a terminal — columns and quoted names ('with space'); in a pipeline (ls | …) — one name per line without quotes.
  • ls -l directory shows the contents, not the directory's permissions. For the directory itself — -d.
  • A link to a directory: ls link shows the target's contents, while ls -l link shows the link itself (ld -> d). Add a trailing / (ls -l link/) or -L to look inside.
  • The directory size in -l (4096) isn't the size of its contents. To see how much the whole directory takes up, use du.
  • -t, -S and -r with file arguments sort only the files; directories from the arguments are still printed as separate blocks after them — add -d.
  • --block-size=K rounds up: a 1530-byte file shows as 2K.
  • Colors. A bash script has no ls --color=auto alias — without --color the output isn't colored. With --color=always, escape codes end up in a file.

See also

stat · find · chmod · df-du · ln · acl