ls
Overview
ls lists directory contents. Combined with options for long format, sorting, and classification, it is the primary tool for inspecting the filesystem tree from the shell.
Syntax
ls [options] [file...]Common Options
| Option | Description |
|---|---|
-l |
Long format (mode, owner, size, mtime) |
-a / -A |
All (include ./..) / almost all (hide ./..) |
-h |
Human-readable sizes (with -l) |
-r |
Reverse sort |
-t / -S |
Sort by mtime / size |
-R |
Recursive |
-1 |
One per line |
-d |
List directories themselves, not contents |
-F |
Classify (/, *, @, …) |
--color=auto |
Colorize |
-i |
Inode numbers |
-X |
Sort by extension |
Examples with Explanations
Everyday
ls
ls -la
ls -lah /var/logSort by time / size
ls -lt # newest first
ls -lt | head
ls -lS # largest firstDirectories only
ls -d */
ls -ld /etc /varRecursive (prefer tree/find for big trees)
ls -R src | headOne column for scripts
ls -1 *.mdInodes and classification
ls -li
ls -FNotes & Pitfalls
- Aliases often map
lstols --color=auto; scripts should callcommand lsor/bin/lsif needed. - Locale affects sort order.
- For recursive size, use
dunotls -R.