← All guides
Command lineBeginner

The Linux command line: a field guide

Build a durable mental model for navigating files, composing commands, reading help, and working safely in any Linux shell.

The terminal is not a list of magic words. It is a small language for connecting programs. Once that clicks, you stop memorizing isolated commands and start solving problems.

Start with the three places that matter

Every shell session has a working directory, every file has a path, and every command can receive input and produce output.

pwd                 # where am I?
ls -lah             # what is here?
cd /var/log         # go somewhere
cd -                # go back

Absolute paths begin at /. Relative paths begin where you are. . means the current directory and .. means its parent. Prefer tab completion over typing long paths; it is faster and prevents mistakes.

Commands are composable

A command usually has a program, options, and arguments:

grep --ignore-case "error" /var/log/syslog

Here grep is the program, --ignore-case changes its behavior, and the remaining values are arguments. Most tools explain themselves through --help; deeper documentation lives in manual pages:

grep --help
man grep

Inside man, press / to search, n for the next match, and q to quit.

Connect programs with pipes

The pipe sends one program’s standard output into another program’s standard input:

journalctl --since today | grep -i "failed" | less

Read this from left to right: get today’s logs, keep lines containing “failed,” then open the result in a pager. This is the Unix idea in miniature—small tools, connected deliberately.

Redirect output when you want to save it:

ip address > network-snapshot.txt
uname -a >> network-snapshot.txt

> replaces a file. >> appends. Check the destination before pressing Enter.

Search without wandering

Use find for files and grep or rg for text:

find ~/Documents -type f -name '*.pdf'
rg -n "listen_port" /etc 2>/dev/null

The second command searches recursively, prints line numbers, and hides permission errors. When you do not know a command name, try apropos archive, your package manager’s search, or a web search that includes your distribution.

Work safely

The shell assumes you mean what you type. Build these habits early:

  1. Run destructive commands on the smallest explicit path possible.
  2. List or print a path before removing or moving it.
  3. Quote paths containing spaces: cd "Project Files".
  4. Avoid copying commands you cannot explain, especially those using sudo.
  5. Keep a second terminal open while changing networking or remote access.

sudo is not “make it work.” It runs a command with elevated privileges. Use it only when the operation actually changes the system rather than your own files.

A 15-minute practice loop

Create a disposable directory and explore:

mkdir -p ~/lab/cli-practice
cd ~/lab/cli-practice
printf 'alpha\nbeta\ngamma\n' > names.txt
wc -l names.txt
sort names.txt | tail -n 2
cp names.txt names.backup
diff -u names.txt names.backup

You just created, inspected, transformed, copied, and compared data. Repeat with your own examples. Fluency comes from short, frequent sessions—not from memorizing a cheat sheet in one evening.

Keep this mental model

Files are objects with paths. Processes read input and write output. Pipes connect processes. Permissions decide who may act. Your shell is the place where those ideas meet.