Before there were buttons and windows, there was a blinking cursor waiting for you to type. That cursor is still there, under every app you use. This lesson is your first conversation with it: what a terminal is, how to type a command, and how to read what comes back.
Difficulty: Beginner · Know this first: F10 — Data vs Information
You open a terminal for the first time. A prompt blinks at you. Nothing is broken. It is just waiting for words.
A first terminal session is mostly reading, not typing. The bar below is a teaching example for this lesson, not a measurement from a live system. It shows where 100 units of a beginner's attention go during one session.
Extra diagram · from scratch to master
Start with your fingers. Add one box at a time until a typed line becomes an answer on the screen.
Extra diagram · from scratch to master
Five commands, five jobs. Learn these five and you can orient yourself on any machine you ever sit down at.
The simulator below is a small terminal that lives in this page. Type a command and press Enter, or click Run. It only knows a few commands, and that is the point: a real terminal starts exactly this small. Try help first, then pwd, ls, whoami, echo hello, and date. Try a typo too, and watch what the computer says.
Press Enter or click Run. Commands this terminal knows: help, pwd, ls, whoami, echo, date, clear. Anything else gets a plain command not found.
Try this: (1) Run pwd. The answer is /home/mohan. (2) Run echo hello world. The computer repeats your words back. (3) Run pbd. The computer says command not found, and nothing breaks. (4) Run clear to wipe the screen and start over.
Three questions. No score is saved anywhere — this is just you against the material.
I take the same idea four times here. First I type one command and read one answer. Then I learn the handful of commands that orient me. Then I chain commands together. Last I run them for the world.
Definition: A terminal is a program that takes your typed lines and runs them. A command is one line that tells the computer to do one thing. Output is what it prints back. The prompt is the computer waiting for the next line.
Types:
Uses: I use these five the first time I sit down at any machine. They tell me where I am, what is around me, and who I am, before I touch anything else.
Dimensions: At this size everything is one line and one answer. What breaks first is my spelling, and I notice it from the command not found message. It costs nothing to try a command. It costs real time when I skip reading the output. The trade is simple: type less, read more.
Definition: At this level I know twenty or so commands and I know what each one is for: looking at files, moving around, reading text, checking the system. I also know flags, which are extra words that change how a command behaves, like ls -l for the long listing.
Types:
Uses: I use this level daily. Most of my on-call work is reading: reading logs, reading configs, reading what the machine says about itself. The terminal is where that reading happens.
Dimensions: As the command list grows, my memory grows with it, and the history helps: the up arrow brings back the last command. What breaks is a flag I misremember, and I notice it from output that looks wrong. It costs a quick check of the manual. The trade is that flags buy precision, and they cost memorisation, so I keep a cheat sheet and I am not ashamed of it.
Definition: At this level one command feeds the next. A pipe sends the output of one command into another. A redirect saves output to a file. A small script runs ten commands in order. The terminal stops being a place to type and becomes a place to build.
Types:
Uses: I use this when a job repeats. The third time I type the same five commands, I stop and write them down as a script. The script never mistypes, never forgets a step, and runs at 3 AM without me.
Dimensions: At ten times the work the script grows, and the risk moves from typing to logic: a wrong loop can touch a thousand files instead of one. What breaks is a script I wrote in a hurry, and I notice it from the output it printed before I stopped it. It costs a dry run with echo first. The trade is that scripts buy speed and repeatability, and they cost the care of testing them on something unimportant first.
Exit codes are the answer. Every command ends with a number. Zero means it worked. Anything else means it failed, and the number says how. I check the code when a command fails, because the code is more honest than the message. A missing file gives 2. A plain failure gives 1.
$ ls /nope 2>/dev/null; echo $?
2
$ false; echo $?
1
Every flag in the commands above, letter by letter.
ls /nope: ls lists the path you give it. /nope does not exist, so ls fails. The path is the argument. The command is the same with any path.2>/dev/null sends error messages away. The 2 is stderr, the error stream. /dev/null is a black hole. Without it, the error prints on screen. With it, the failure is silent, and only the exit code tells you what happened.echo $? prints the exit code of the last command. 2 means ls could not find the file. 1 means false failed, which is its whole job. 0 means success.false takes no flags. It always fails with exit code 1. It exists so scripts can test failure on purpose.ls itself, letter by letter: -l is the long listing, with permissions, owner, size, and date. -a shows hidden files, the ones starting with a dot. -h prints sizes as 12K instead of 12288, and only matters with -l. -t sorts newest first. -r reverses the order. Put them together and ls -lrth means long listing, human readable, newest last. That is the form I type when I want to see what changed recently.Check it: run ls, then ls -l, then ls -lrth. The first prints names. The second adds sizes and dates. The third sorts oldest first and newest last, so the file you just touched sits at the bottom.
Try it: run both commands. The first fails because the file does not exist, and the code is 2. The second fails on purpose, and the code is 1. When a script fails, I print $? right after the failing line. That number is the first clue.
Check before you trust. A script with a typo fails halfway through, after it has already done half the work. I check the syntax first with bash -n. It reads the script without running it. If it prints nothing, the syntax is clean.
$ printf 'echo hello\n' > check.sh
$ bash -n check.sh && echo syntax-ok
syntax-ok
$ bash check.sh
hello
Every flag in the commands above, letter by letter.
printf takes no flags here. It writes the script file, so there is something to check and run.bash -n: -n checks the syntax and runs nothing. It reads the file and reports errors. If it prints nothing and the next command runs, the syntax is good.bash check.sh runs the script. No flag means run it for real.bash -x prints each line before it runs it. The trace shows exactly which line failed. When a script breaks, -x is the first flag I add.Check it: run bash -n check.sh && echo syntax-ok. It prints syntax-ok. Add a typo to the script and run bash -n again. It prints the error and the line number. Then run bash -x check.sh and watch each line print before it runs.
Try it: create the script above and run the check. It prints syntax-ok. Now add a typo, like a missing quote, and run the check again. It prints an error and the line number. Fix the typo and the check passes again.
Definition: At this level commands run on machines I will never sit in front of, through SSH, inside containers, across fleets. The same loop applies: type, read, repeat. The difference is that a mistake now touches production, so every destructive command gets a second pair of eyes: a dry run, a confirmation, a backup.
Types:
Uses: I use this when the machine is a server in another city. The terminal is the same. The stakes are higher, so the habits are stricter: read before Enter, echo before delete, never paste a command I did not read.
Dimensions: At a hundred machines the command is the same and the blast radius is a hundred times bigger. What breaks is a command pasted from a chat message without reading it, and I notice it from the output scrolling past too fast to stop. It costs discipline: dry runs, confirmations, and a rule that nobody pastes a command they cannot explain. The trade is that remote power buys reach, and it costs the humility to go slow.
Stop on the first failure. A script that keeps going after a failure does more damage than the failure itself. I put set -e at the top, so the script stops at the first command that fails. The rest of the script never runs, and the damage stops there.
$ bash -c 'set -e; false; echo reached'; echo $?
1
$ bash -c 'set -e; true; echo reached'; echo $?
reached
0
Every flag in the commands above, letter by letter.
bash -c: -c runs the string that follows as a script. The quotes hold the whole script. Without -c, bash expects a filename.set -e: -e means exit at the first failing command. The script stops at false and never prints reached. Without -e, the script keeps going after a failure, and the later lines run on broken assumptions.true takes no flags. It always succeeds with exit code 0. It is the twin of false.set -u stops the script if it uses a variable that was never set. Without it, the empty value is used silently, and the script does the wrong thing with no error.Check it: run bash -c 'set -e; false; echo reached'; echo $?. It prints 1 and never prints reached. Then run bash -c 'set -u; echo $UNSET_VAR_HERE'; echo $?. It prints unbound variable and 127.
Try it: run both commands. The first stops at false and never prints reached. The second passes true and prints it. Every script I write for real work starts with set -e. A script that stops early is a script that fails safely.
The shell is a program, not the computer itself. When you type, you are talking to the shell, and the shell talks to the kernel, and the kernel talks to the hardware. Knowing there is a translator in the middle explains half the errors you will ever see: most of them are the shell telling you it could not find, could not read, or could not understand something.
Commands are small programs. ls is a program. grep is a program. The shell finds them, runs them, and shows you what they printed. That is why the list of commands can grow: anyone can write a new program, give it a name, and the shell will run it like any other.
Flags change a command the way adverbs change a verb. ls lists files. ls -l lists them with details. ls -a shows the hidden ones too. The command is the same. The flag changes what you get back. I learn one flag at a time, when I need it, not from a list.
The up arrow is the best beginner feature in the whole terminal. It brings back the last command you typed. Up twice brings back the one before that. Most of my terminal life is re-running a command I typed five minutes ago with one small change.
History is a record of what you did. The shell keeps the commands you typed, in order. On a bad day, that history is how I work out what I actually did, step by step, instead of what I remember doing. Memory lies. History does not.
At 10x the work, the habit that matters most is reading before pressing Enter. The terminal does not ask are you sure. It does what you typed. The only confirmation dialog is the one in your head, and it has to be trained.
$ pwd
/home/mohan
$ ls
notes.txt todo.md photos
$ whoami
mohan
$ echo hello
hello
$ date
Thu Nov 19 23:30:59 CST 2026
Every flag in the commands above, letter by letter.
pwd prints where you are. ls lists what is here. whoami prints who you are logged in as. echo repeats your words. date prints the time. The flags live on ls, in the box above, not here.clear takes no flags either. It wipes the screen and puts a fresh prompt at the top. It deletes nothing. The scrollback is still there if you scroll up.date -u prints the time in UTC instead of local time. Logs and servers compare times in UTC. When I compare a log line with a clock on another machine, -u removes the timezone from the question.Check it: run date, then date -u. On a machine set to Chicago time, the two differ by 6 hours. On a machine already set to UTC, they print the same time, and that itself is worth knowing.
What the snippet means: five commands and five answers. Each line starting with $ is what I typed. Each line after it is what the computer printed. Read them top to bottom and you have the whole lesson in ten lines.
Try it: a check script of your own. Write a script that prints the disk use, check its syntax with bash -n, then run it. The check costs one command and it catches the typo before the script runs. A script that fails halfway is worse than a script that never starts.
$ printf 'echo hello\n' > check.sh
$ bash -n check.sh && echo syntax-ok
syntax-ok
$ bash check.sh
hello
I was practising in a scratch folder and I wanted to clear it out. I typed a delete command, pressed Enter, and watched the prompt come back instantly. Too instantly. I had typed the path wrong, and the command had deleted the folder above the one I meant. It held a week of notes. The command did exactly what I typed. That was the problem.
Three things. First, I never delete from a typed path again: I navigate to the folder first, look at it with ls, and then delete by name. Second, I echo the full delete command before running it, so my eyes see the path once more. Third, I keep a backup that runs every night, because the day will come when a rule is not enough. The lesson was not that delete is dangerous. The lesson was that I skipped the two seconds of checking that would have caught the typo.
Write a first-day cheat sheet for a new teammate who has never opened a terminal. Five commands, one line each, in the order they should learn them. Then write the three rules that keep a beginner from hurting anything.
Five commands fit on one page. Ten commands do not, because nobody reads ten. I put pwd, ls, whoami, echo, and date on the sheet, in that order: where am I, what is here, who am I, say it back, what time is it. The three rules are: read before Enter, never delete from a typed path, and use a scratch folder for practice. The sheet takes an hour to write and saves a week of confusion.
A short sheet buys learning and costs completeness. A long sheet buys completeness and costs the chance anyone reads it. Safe commands buy confidence and cost realism, because real work is not always safe. Teaching the delete command early buys honesty and costs risk, so I teach it last, in a folder that holds nothing I care about.