The Terminal: A Practical Guide

Published Updated

The terminal gives you a text interface to the operating system. A graphical app works like a front desk that offers prepared forms and buttons, while the terminal gives you a direct phone line where precise requests receive precise responses.

On macOS, open Spotlight, search for Terminal, and press Return. On Linux, open Terminal from the applications menu. On either system, type a command at the prompt, then press Return to run it.

Windows needs one setup pass first: install WSL.

  1. Search for PowerShell in the Start menu, right-click it, and choose Run as administrator, because the install needs elevated permissions.
  2. Run wsl --install, then restart your computer.
  3. After the restart, search for Ubuntu or WSL in the Start menu and open it to reach the Bash prompt used in these examples.
  4. The first start asks you to create a Linux username and password; this is expected, not an error.

mkdir creates a folder, the -p option also creates any missing parent folders (dash-letter additions like -p are called options), and $HOME is your personal folder.

mkdir -p "$HOME/terminal-practice"
cd "$HOME/terminal-practice"
pwd
# /Users/your-name/terminal-practice

Lines starting with # in these examples show what the terminal prints back, so do not type them.

On Linux, the final path usually begins with /home instead of /Users. The commands create a safe practice directory, enter it, and print its full location. Keep using this directory as the examples add files and folders.

What the Terminal and Shell Do

A terminal is the application that shows a prompt, accepts keyboard input, and displays output. Apple's Terminal application on macOS is one familiar example. Other terminal applications provide different tabs, colors, fonts, and shortcuts while doing the same basic job.

The shell is the command interpreter running inside the terminal. It reads a command, expands variables such as $HOME, finds the requested program, connects its input and output, and reports the result. macOS uses zsh as its default shell. Bash remains common across Linux distributions, although users can choose another shell.

The terminal carries text between you and the shell. The shell interprets each request and routes it to commands such as ls, cp, or grep.

How to Read the Prompt

The prompt marks the point where the shell is ready for another command. Its exact appearance depends on the shell and configuration, but it often includes a username, computer name, current directory, and final prompt symbol.

alex@laptop terminal-practice %

In this prompt, alex@laptop identifies the user and computer, while terminal-practice is the current directory. The percent sign is common in zsh prompts, while Bash prompts often end with a dollar sign. A root or administrator shell commonly ends with a hash sign. Do not copy the prompt text when a tutorial shows commands prefixed with $ or %; type only the command after it.

Terminal navigation begins with three commands you will use constantly. pwd prints the working directory, ls lists its contents, and cd changes the working directory. A relative path starts from your current location, while an absolute path starts from the filesystem root.

mkdir -p "$HOME/terminal-practice/reports"
cd "$HOME/terminal-practice"
pwd
# /Users/your-name/terminal-practice
ls
# reports
cd reports
pwd
# /Users/your-name/terminal-practice/reports
cd ..
pwd
# /Users/your-name/terminal-practice

The first pwd prints the practice directory, ls shows the new reports folder, and the later pwd commands confirm each move into and out of that folder.

The two dots in cd .. mean the parent directory. A single dot means the current directory, and cd without a path returns to your home directory. Run pwd before a file operation whenever the prompt does not make your location obvious.

Create, Copy, Move, and Remove Files

File operations follow the same path rules. mkdir creates a directory, cp copies a file, mv moves or renames it, and rm removes it. The next sequence creates a note, copies it, renames the copy, then removes only that copy. printf writes the text, and > sends it into the file; redirection is covered fully below.

cd "$HOME/terminal-practice"
mkdir -p drafts
printf "Deploy at 10:00\n" > drafts/deploy-note.txt
cp drafts/deploy-note.txt deploy-note-copy.txt
mv deploy-note-copy.txt final-deploy-note.txt
ls
# drafts  final-deploy-note.txt  reports
rm final-deploy-note.txt
ls
# drafts  reports

The second listing confirms that final-deploy-note.txt was removed. The original file still remains at drafts/deploy-note.txt after this sequence finishes. Both cp and mv take a source followed by a destination, so read them as "copy this to there" and "move this to there." That order matters when two paths look similar.

Read and Search Text

cat writes a file to standard output, which is normally the terminal. That makes it a sensible choice for short files. less opens a scrollable viewer for longer files, and grep prints lines that match a pattern.

cd "$HOME/terminal-practice"
printf "INFO server started\nERROR disk full\nINFO retrying\nERROR backup failed\n" > deployment.log
cat deployment.log
# INFO server started
# ERROR disk full
# INFO retrying
# ERROR backup failed
grep "ERROR" deployment.log
# ERROR disk full
# ERROR backup failed
less deployment.log

The first four output lines come from cat, and the next two are the matches from grep. The less viewer then opens the file without loading it into an editor. Press the arrow keys to move and q to return to the prompt.

Connect Commands with Pipes and Redirection

Every command can receive standard input and produce standard output. In the front-desk and phone-line metaphor, a pipe transfers the call from one department to the next, so each command handles one part of the request. Redirection takes the reply and files it at a named destination: > creates or replaces the file, while >> appends without removing existing content.

grep "ERROR" deployment.log | sort > errors.txt
printf "ERROR network timeout\n" >> errors.txt
cat errors.txt
# ERROR backup failed
# ERROR disk full
# ERROR network timeout
wc -l < errors.txt
# 3

The worked chain searches the log, sends both matching lines through sort, and writes the alphabetized result to errors.txt. The next command appends another error without replacing the first two. Finally, wc -l receives the file as standard input and reports three lines.

Check the destination before using >, because an existing file is truncated before the command writes new output. Use >> only when repeated runs should keep earlier content.

Why the Terminal Matters for AI Coding Agents

Command-line AI coding agents operate from a project directory, so terminal basics help you set their scope and inspect the commands shown on screen. Claude Code, Codex CLI, and opencode are three widely used agents launched from a terminal, and new terminal agents keep arriving because the terminal gives them direct access to files, commands, and version control.

cd "$HOME/projects/weather-dashboard" && pwd && ls

You do not need to memorize every shell command first. Recognizing the current directory, reading command output, and checking whether an operation targets the intended path lets you review what appears in the terminal. In this example, pwd and ls confirm the project in scope before the agent starts.

The full supervision workflow for approvals, reviewing changes, and safety boundaries lives in the dedicated terminal AI agents guide.

Common Pitfalls & Debugging

Removed Files Bypass the Trash

Symptom: a removed file does not appear in the desktop Trash. Cause: rm unlinks files directly instead of moving them into a recovery folder. Fix: run pwd and ls first, name the exact target, and keep version control or backups for anything that matters. Avoid recursive removal until you understand every path involved.

Spaces in Paths Need Quoting

Symptom: cd reports too many arguments or a command treats one path as several inputs. Cause: the shell splits unquoted spaces into separate words. Fix: wrap the complete path in straight double quotes.

mkdir -p "$HOME/terminal practice"
cd "$HOME/terminal practice"
pwd
# /Users/your-name/terminal practice

Command Not Found Points to PATH

Symptom: the shell reports command not found for a name you expected to run. Cause: the name is misspelled, the program is not installed, or its directory is absent from PATH, the list of directories the shell searches for commands. Fix: check the spelling, use command -v to locate known commands, and inspect the search path before changing shell configuration.

command -v grep
# /usr/bin/grep
echo "$PATH"
# /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Administrator Permissions Need Extra Caution

Symptom: a command asks for a password or changes protected system files. Cause: sudo runs an authorized command with elevated permissions. Fix: stop and read the complete command before entering a password. Do not add sudo merely because an installation or file command failed.

Filename Case Can Change Between Systems

Symptom: a path works on one computer and fails on another. Cause: Linux filesystems are commonly case-sensitive, while the default macOS volume is usually case-insensitive but case-preserving. Fix: match filename case exactly in commands, imports, and scripts so the same path works in both environments.

Conclusion

Terminal work becomes manageable when each command has a clear location, input, and output. Practice in the dedicated directory until navigation, file operations, pipes, and redirection feel predictable. Those habits also make command-line coding agents easier to supervise.

Frequently Asked Questions

What is the difference between a terminal and a shell?

The terminal is the application that displays text input and output. The shell is the program running inside it that reads commands, expands paths and variables, launches other programs, and returns their output to the terminal.

Are terminal commands the same on Mac and Linux?

Many navigation and file commands are shared because macOS and Linux are Unix-like systems, but options and implementations can differ. PowerShell uses a different command set on Windows. WSL provides a Linux environment where Bash and common GNU/Linux commands work directly.

Do you need the terminal to use AI coding tools?

No. Some AI coding tools have desktop or editor interfaces. Terminal basics let you start command-line tools such as Claude Code and Codex CLI from the intended project directory, read their output, and check paths before running commands.

How do you recover from a wrong terminal command?

Press the up-arrow to inspect the last command or run history to review earlier commands. Ctrl+C usually interrupts the foreground command, although some programs can catch or ignore it. Check the command and its output before deciding what to do next.

Does tab-completion work the same way for commands as it does for file paths?

Tab completion behaves differently depending on position: at the start of a line the shell completes command names from PATH, while after a command it completes file and directory names from the current location. Both stop at the first ambiguous character and expand further only once the remaining text is unique.

Self-Check

  1. Which macOS tool can open Terminal quickly: Spotlight, Finder Tags, Disk Utility, or Preview?
  2. What does the pwd command print?
  3. What does printf "ERROR two\nINFO one\nERROR one\n" | grep "ERROR" | sort print?
  4. Which operator appends output without replacing the existing file: >, >>, |, or <?
  5. Which command shows earlier shell commands so you can inspect one before running it again?

Answers

  1. Spotlight. Search for Terminal there, then press Return to open it.
  2. The full path of the working directory. It confirms where relative paths and file commands will begin.
  3. ERROR one, then ERROR two. grep keeps the matching lines and sort orders them alphabetically.
  4. >>. A single > replaces the destination, while two angle brackets append to it.
  5. history. It prints earlier commands so you can review their paths and arguments before reuse.

Sources

  1. [1]
    Terminal User Guide for Mac
    (support.apple.com)
  2. [2]
  3. [3]
  4. [4]
  5. [5]
  6. [6]
  7. [7]
  8. [8]
    Windows Subsystem for Linux
    (learn.microsoft.com)
  9. [9]
    Claude Code CLI Reference
    (code.claude.com)
  10. [10]
    Codex CLI Documentation
    (learn.chatgpt.com)