Start With the Problem#
It's 11 p.m. StudyBuddy is down. Students have an exam tomorrow. You connect to the server in Mumbai, and you see…
priya@studybuddy-prod-1:~$ ▌A blinking cursor. No desktop, no mouse, no windows, no Finder. Servers don't have screens — that would waste memory on something nobody looks at.
You need to: find out if the app process is running, read its error logs, check if the disk is full, see what's using the memory, restart the app, and confirm it's answering on port 8000.
Every one of those is a few keystrokes — if you know the language. This file teaches that language.
The Plain Picture#
Imagine texting a very capable, very literal assistant. You send an instruction, they do it, and they reply with the result — or with an error if you said something they didn't understand. You never see them working; you only see the chat.
The Real Names#
The terminal is the chat window: the app that shows text and sends your keystrokes (Terminal or iTerm2 on Mac).
The shell is the assistant: a program that reads your command, runs it, and shows the output. It's a normal process (Operating Systems Ch 3). Common shells:
bash — the default on most Linux servers.
zsh — the default on macOS (yours). They're almost identical for everything in this file.
The prompt is the text before your cursor:
priya@studybuddy-prod-1:~$means userpriya, on machinestudybuddy-prod-1, in folder~(home, Ch 2).$= normal user;#= the all-powerful admin user root (Ch 4).
Under the Hood — the shape of every command#
ls -l -a /var/log │ └──┬──┘ └───┬───┘ │ options arguments command (the program to run)
Command — the program's name.
lsis actually a program file,/bin/ls.Options (or flags) change how it behaves. Short ones: one dash, one letter (
-l), and they can be combined (-la=-l -a). Long ones: two dashes, a word (--all).Arguments — what to act on (a file, a folder, a URL).
When you press Enter, the shell finds the program (Ch 8), starts it as a child process with fork + exec
(Operating Systems Ch 3), connects its stdin/stdout/stderr to your terminal, and waits for it to exit.
Getting help:
man ls # the full manual ("man page"). Arrow keys to scroll, / to search, q to quit
ls --help # a shorter summary (on Linux; macOS's built-in ls doesn't support --help)
tldr tar # practical examples (install first: brew install tlrc)Keys that save hours:
| Key | What it does |
|---|---|
| Tab | auto-complete a file or command name. Press twice to list options. Use it constantly. |
| ↑ / ↓ | previous / next command from history |
| Ctrl+R | search your history: type part of an old command |
| Ctrl+C | stop the running command (sends SIGINT — Operating Systems Ch 12) |
| Ctrl+D | "end of input" — exits the shell if the line is empty |
| Ctrl+L | clear the screen |
| Ctrl+A / Ctrl+E | jump to start / end of the line |
Check yourself
4 questionsWhat's the difference between the terminal and the shell?
Show answerHide answer
The terminal is the window that displays text; the shell is the program that interprets and runs your commands.
In grep -rn "error" /var/log, what are the command, the options and the arguments?
Show answerHide answer
Command grep; options -r -n; arguments "error" and /var/log.
What does a # at the end of the prompt warn you about?
Show answerHide answer
You're root — the admin user who can do anything, including destroy the system.
What does Ctrl+C actually do?
Show answerHide answer
Sends SIGINT to the running program, asking it to stop.