ls
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 -1Sorting and time
ls -lt --time-style=long-iso
ls -ltu # sort by atime
ls -lc # sort by ctimeRecursive (careful)
ls -R /etc/ssh
# for deep trees prefer tree/find
tree -L 2
find /etc/ssh -maxdepth 2Classification and inodes
ls -F
ls -li
ls -lH # follow link for size/mtime display variantsGlobs 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 useColor and aliases
ls --color=auto
alias ll='ls -lah --group-directories-first'Compare modern alternatives
ls -lah
eza -lah --git # if installedUnderstanding 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
lsin scripts is fragile — usefind,stat, or shell globs. - Locale affects sort order and date formats; set
LC_ALL=Cfor stable ASCII sort. lsof a symlink without-lmay show the name only; details need-l/-L.- Huge directories:
lssorts by default and can be slow; try-Uorfind. - SELinux systems:
-Zshows security context (GNU ls).
2026-relevant notes
- Many desktops alias
lsto colorized forms; usecommand lswhen you need vanilla behavior. eza/lsd/ls++improve UX; still teach classic flags for SSH to minimal servers.- Combine with
bat/less -Rwhen piping colorized output.
Additional Resources
man ls