ch01/l02

Listing as inspection

Choose listing views based on the question you need answered.

ls -la 20 min read, 25 min lab beginner

`ls` can answer different questions: names, hidden entries, permissions, ownership, sizes, times, and file type hints. The default view is rarely enough for troubleshooting.

In the field

A service refuses to read a config file. You need to check owner, group, mode, and timestamp without editing the file.

Worked command

$ ls -la /etc/ssh$ ls -lhtr /var/log | tail$ stat /etc/passwd
Anti-pattern

Do not parse `ls` output in scripts; use it for human inspection.

Safer pattern

Use long listings for metadata and `stat` when one file's exact details matter.

Knowledge check

A service can't read one config file and you need its exact owner, group, mode, and timestamp. Which command answers that best, and why?

  • A `pwd`, because it confirms you are in the right directory first
  • B `ls`, because the default view already lists permissions
  • C `stat`, because it reports exact metadata for a single file
  • D `ls -la` parsed in a script, because columns are machine-readable
Show the answer

Correct: C. `stat`, because it reports exact metadata for a single file

Why

`stat` is built to report one file's exact owner, group, mode, and times; `ls`'s default view shows only names, and parsing `ls` output is unreliable and discouraged for scripts.

Practice checklist

  1. Create files including a dotfile.
  2. Compare `ls`, `ls -a`, `ls -la`, and `stat`.
  3. Write what each view proves.

Deliverable evidence

  • A table mapping each listing command to the fact it proved.
Teaching diagramch01 · mental model
Every path resolves to one absolute location cwd pwd shows it . here .. parent ~ home /abs/target realpath proves it find /var/log -type f -name '*.log' -mtime -1 walks the tree, filters to evidence absolute path = same target from anywhere | relative path = depends on cwd

shows: How `.`, `..`, and `~` resolve from the current directory into a single absolute location, with `pwd`/`realpath` confirming where you actually are and `find` filtering a tree down to evidence.

does not prove: It shows how path tokens resolve in principle; it does not prove your shell's current directory at any moment — only running `pwd` or `realpath` on the live machine proves that.

Memorize this

Commit these to memory, then drill them until recall is automatic.

lsls -als -lals -lhtrstat
Recall practice · Meaning -> command

cue Show hidden entries plus permissions, ownership, size, and time for everything in a directory.

show recall target

ls -la