kmail.at
← learning

linux · difficulty ◆

ls — list directory contents

See what is in a directory, the way Unix intends.

You probably think ls is trivial — a command so basic you learned it on day one. Then you meet its flags and realize most people never get past the first three.

2026-08-12 · 4 min read

$ ls

What it does

ls prints the contents of a directory (or directories). It is the single most-used command in a shell session: every time you need to know what is in a folder, ls is there. It supports colors, sorting, timestamps, and long-form output.

Why it matters

Before ls, early Unix users had no portable way to browse the filesystem. ls became the universal "what is here?" — and its flags (especially -l and -a) are the foundation for everything else you do with files.

Example

$ ls -l
total 24
-rw-r--r-- 1 kmail kmail  1234 Aug 13 09:10 notes.md
-rwxr-xr-x 1 kmail kmail  5678 Aug 13 09:12 run.sh
drwxr-xr-x 2 kmail kmail  4096 Aug 13 09:15 src

-l gives long format: permissions, owner, size, date, name.

$ ls -la
total 28
drwxr-xr-x 5 kmail kmail  4096 Aug 13 09:10 .
drwxr-xr-x 3 kmail kmail  4096 Aug 12 18:00 ..
-rw-r--r-- 1 kmail kmail  1234 Aug 13 09:10 notes.md
-rw-r--r-- 1 kmail kmail   220 Aug 13 09:11 .env

-a shows hidden dotfiles (anything starting with a .).

Common flags

-l
long format with permissions, owner, size, date
-a
show all files, including dotfiles (. and ..)
-h
human-readable sizes (K, M, G) — pairs with -l
-t
sort by modification time, newest first
-r
reverse sort order
-S
sort by file size, largest first

History

Origin

ls appeared in the first edition of Unix (1971) at Bell Labs, written by Ken Thompson and Dennis Ritchie. The name is a shortening of the verb "list". Its flag style — single letters with no leading dash required in the earliest versions — set the pattern every later Unix command followed.

Fun fact

GNU coreutils ls and the BSD ls diverge slightly in defaults. On many systems ls is actually an alias (e.g. "ls --color=auto") so colors just work. The classic 4.0BSD manual described ls as "list directory contents".

Fun facts

Pros & cons

pros

  • + Always present on every Unix-like system — no install needed
  • + Combines formatting, sorting, and filtering in one tool
  • + Fast: it reads directory entries directly, no per-file stat unless you ask

cons

  • − Defaults are bare; most people need -l, -a, or -h to see anything useful
  • − No cross-filesystem recursion like find
  • − Output is locale-sensitive, which can trip scripts parsing it

Takeaways

  1. 1Start every session with `ls -la` to see the truth about a directory
  2. 2Pair -h with -l so sizes become human-readable (K, M, G)
  3. 3Use -t to find the most recently modified file in a busy directory
  4. 4Add the --color=auto alias so you are not squinting at plain text
  5. 5When scripts need stable output, use `ls -1` (one entry per line)

Related commands

← all learning