ls

Updated

September 4, 2026

Overview

ls lists directory contents. With long format, sorting, and classification options it is the primary interactive tool for inspecting the filesystem tree. Prefer eza/lsd if installed for richer defaults; every admin still needs classic ls for scripts and minimal systems.

Syntax

ls [options] [file...]

Common Options

Option Description
-l Long format (mode, links, owner, group, size, mtime, name)
-a / -A All (include ./..) / almost all (hide ./.. only)
-h Human-readable sizes (with -l)
-r Reverse sort
-t / -S / -u / -c Sort by mtime / size / atime / ctime
-R Recursive
-1 One entry per line
-d List directories themselves, not their contents
-F Classify (/ dir, * exec, @ symlink, …)
-i Inode numbers
-s Size in blocks
--color=auto Colorize when stdout is a tty
-X Sort by extension
-U Do not sort (directory order)
--group-directories-first Dirs before files (GNU)
-N Show raw names (less escaping)
-L Follow symlinks for file info

Examples with Explanations

Everyday

ls
ls -la
ls -lah
ls -lt                 # newest first
ls -lS                 # largest first
ls -1

Hidden and directories

ls -A
ls -ld /var/log        # info about the dir itself
ls -ld .??*            # hidden entries without . and ..

Sorting and time

ls -lt --time-style=long-iso
ls -ltu                # sort by atime
ls -lc                 # sort by ctime

Recursive (careful)

ls -R /etc/ssh
# for deep trees prefer tree/find
tree -L 2
find /etc/ssh -maxdepth 2

Classification and inodes

ls -F
ls -li
ls -lH                 # follow link for size/mtime display variants

Globs and multiple paths

ls -l *.md
ls -ld /etc /var /usr
ls /usr/bin/python*

Scripts: stable output

ls -1
ls -1 --quoting-style=shell-escape
# parse carefully; prefer find -print0 for machine use

Color and aliases

ls --color=auto
alias ll='ls -lah --group-directories-first'

Compare modern alternatives

ls -lah
eza -lah --git         # if installed

Understanding long format

-rw-r--r-- 1 alice alice  1234 2026-01-15 10:02 file.txt
\ type+mode  links owner group size mtime       name

Leading type char: - file, d directory, l symlink, b/c devices, p fifo, s socket.

Notes / Pitfalls

  • Output columns are for humans; parsing ls in scripts is fragile — use find, stat, or shell globs.
  • Locale affects sort order and date formats; set LC_ALL=C for stable ASCII sort.
  • ls of a symlink without -l may show the name only; details need -l / -L.
  • Huge directories: ls sorts by default and can be slow; try -U or find.
  • SELinux systems: -Z shows security context (GNU ls).

2026-relevant notes

  • Many desktops alias ls to colorized forms; use command ls when you need vanilla behavior.
  • eza/lsd/ls++ improve UX; still teach classic flags for SSH to minimal servers.
  • Combine with bat/less -R when piping colorized output.

Additional Resources

  • man ls