ls is the command you type more than any other. It lists what is in a directory, and with the right flags it answers most "what is actually here?" questions in one line.
Everyday listing #
List files in the current directory
$ ls
apt-keys data public src wrangler.jsonc
Plain ls prints names in columns. That hides more than it shows, so most people settle on a longer form:
The long listing everyone ends up using
$ ls -lh
-rw-r--r-- 1 ana ana 117K Oct 20 02:10 sample.py
drwxr-xr-x 8 ana ana 256 Oct 11 16:03 src
Reading one line left to right: permissions, number of hard links, owner, group, size in a human unit, last modification date, and the name.
The flags that matter #
| Flag | What it does |
|---|---|
-l | Long format with permissions, owner, size, date |
-a | Include hidden dotfiles such as .gitignore |
-h | Human-readable sizes (K, M, G) with -l |
-t | Sort by modification time, newest first |
-S | Sort by size, largest first |
-r | Reverse the sort order |
-d | List the directory itself, not its contents |
-R | Recurse into subdirectories |
Useful combinations #
Newest changes first — the fastest way to find the file you just edited:
Show the most recently modified files
$ ls -lht | head
Everything, including dotfiles, sorted by size:
Find the biggest entries, hidden ones included
$ ls -lhaS | head
Does that directory exist, and what kind of entry is it?
Inspect a directory without entering it
$ ls -ld /etc/nginx
drwxr-xr-x 3 root root 4096 Oct 1 09:12 /etc/nginx
Listing is step one. To search inside files rather than list them, reach for grep. More practical notes live in the journal.
