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 #

FlagWhat it does
-lLong format with permissions, owner, size, date
-aInclude hidden dotfiles such as .gitignore
-hHuman-readable sizes (K, M, G) with -l
-tSort by modification time, newest first
-SSort by size, largest first
-rReverse the sort order
-dList the directory itself, not its contents
-RRecurse 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.