Learn Linux terminal docs
Everything the practice terminal understands: its lessons, its own slash commands, each Linux command and what it leaves out. The lists below are made from the terminal's code, so they always match it.
Start
Open Learn Linux and type a command into the box, then press Enter. Type /lessons to see the lessons and /lesson 1 to start the first. Each step checks itself when you run a command that does the job, so you can type it your own way. Stuck? /hint shows one way to do it.
Everything runs inside the page in your browser. The page's security policy stops it from making any network request, so nothing you type is sent to BuildForPeople or anyone else. The only thing kept is which lessons you finished, in your browser's own storage.
Lessons
Lessons 1 to 6 follow the order and topics of Ubuntu's Command line for beginners tutorial. The wording and practice files are ours, so you can read Ubuntu's version alongside and try the same ideas on a real machine. Where Ubuntu uses sudo, this terminal shows the refusal instead, because you are an ordinary user here.
1. Find your way around
The terminal always works in one folder, called the working directory. These steps move you around the file system with absolute paths, which start at the top with /, and relative paths, which start from where you are. Start it with /lesson 1.
- Print your working directory. One way:
pwd - Go to the very top of the file system, the root folder called /. One way:
cd / - Go into home with a relative path, one with no slash in front. One way:
cd home - Go back up one level. Two dots mean the folder above. One way:
cd .. - Jump straight to the log folder with an absolute path. One way:
cd /var/log - Ask the terminal who you are. One way:
whoami - Go home. cd on its own, or cd ~, always takes you there. One way:
cd ~ - List what is in your home folder. One way:
ls
2. Make folders and files
You'll make a practice folder in /tmp, the place for throwaway files, and fill it. Along the way you'll meet options, quoting, redirects and wildcards. Start it with /lesson 2.
- Make a folder called practice inside /tmp. One way:
mkdir /tmp/practice - Go into it. One way:
cd /tmp/practice - Make three folders with one command: red, green and blue. One way:
mkdir red green blue - Make one/two/three in one go. The -p option makes the folders in between. One way:
mkdir -p one/two/three - Make a folder whose name has a space. Quotes keep the name in one piece. One way:
mkdir "my notes" - Write a line into note_1.txt with echo and >. One way:
echo "first note" > note_1.txt - Make note_2.txt and note_3.txt the same way. One way:
echo "second note" > note_2.txt && echo "third note" > note_3.txt - Print all three with a wildcard. ? stands for any one character. One way:
cat note_?.txt - Join them into all.txt, then add one more line with >>, which adds instead of replacing. One way:
cat note_* > all.txt && echo "added later" >> all.txt - Names care about case. Make b.txt and B.txt, then list them both. One way:
echo lower > b.txt && echo upper > B.txt && ls
3. Move, copy and delete
mv moves and renames, cp copies, and rm deletes for good. There is no bin on the command line, so it pays to look before you press Enter. Start it with /lesson 3.
- Go to /tmp/practice and move all.txt into the red folder. One way:
cd /tmp/practice && mv all.txt red - Bring everything in red back here. A single dot means the folder you are in. One way:
mv red/* . - Move several files at once. The last name is where they all go. One way:
mv all.txt note_* green - Copy all.txt from green back here. One way:
cp green/all.txt . - Rename by moving: call the copy backup.txt. One way:
mv all.txt backup.txt - Spaces in names are a pain to type. Rename "my notes" to my_notes. One way:
mv "my notes" my_notes - Delete backup.txt. It is gone for good. One way:
rm backup.txt - Delete the empty blue folder with rmdir. One way:
rmdir blue - rmdir refuses folders that still hold files. Delete green and everything in it with rm -r. One way:
rm -r green
4. A bit of plumbing
A pipe (|) sends one command's output straight into the next, so small tools join up into bigger jobs without temporary files. Start it with /lesson 4.
- Count the lines in your fruit list. One way:
wc -l ~/notes/fruits.txt - Count the things in your home folder by piping ls into wc. One way:
ls ~ | wc -l - uniq drops a line only when it repeats the one just above it. Try it on the fruit list. One way:
uniq ~/notes/fruits.txt - Sort first, so the repeats sit together, then uniq keeps one of each. One way:
sort ~/notes/fruits.txt | uniq - Count how many different fruits there are. One way:
sort ~/notes/fruits.txt | uniq | wc -l - Read the manual page for uniq. Every command has one. One way:
man uniq
5. The superuser
Linux has one all-powerful account, root, also called the superuser. On your own Ubuntu machine, sudo lets your account run one command as root. Here you are an ordinary user on a shared machine, so you'll see what the refusals look like and why they protect everyone. Start it with /lesson 5.
- Try to read /etc/shadow, where password hashes are kept. One way:
cat /etc/shadow - On your own machine you would put sudo in front. Try it. One way:
sudo cat /etc/shadow - See why it refused: list your groups. Only members of the sudo group may use sudo. One way:
id - Try to install a program with apt, Ubuntu's package manager. One way:
apt install tree - tree is already installed. Draw your practice folder with it. One way:
tree /tmp/practice
6. Hidden files
A name that starts with a dot is hidden. Programs keep their settings in hidden files in your home folder, and ls skips them until you ask. Start it with /lesson 6.
- Go to /tmp/practice. One way:
cd /tmp/practice - Hide b.txt by giving it a name that starts with a dot. One way:
mv b.txt .b.txt - List the folder. The hidden file doesn't show. One way:
ls - Now list with -a. You'll also see . (this folder) and .. (the one above). One way:
ls -a - Make a hidden folder called .secret and move the hidden file into it. One way:
mkdir .secret && mv .b.txt .secret - tree hides dot names too, until you add -a. One way:
tree -a - Count everything in your home folder, hidden files included. One way:
ls -a ~ | wc -l - Clean up after yourself: delete the whole practice folder. One way:
rm -r /tmp/practice
7. Search inside files
grep finds lines that match a pattern. It is how people dig through logs. Start it with /lesson 7.
- Show the lines with ERROR in /var/log/app.log. One way:
grep ERROR /var/log/app.log - Do the same, with line numbers. One way:
grep -n ERROR /var/log/app.log - Find the lines that mention login, whatever the case. One way:
grep -i LOGIN /var/log/app.log - Show the last 3 lines of the log. One way:
tail -n 3 /var/log/app.log - Find every .txt file under your home folder. One way:
find ~ -name "*.txt"
8. Permissions and scripts
Every file says who owns it and who may read, write and run it. You are the ordinary user student, so your files are yours and the system's files are root's. Start it with /lesson 8.
- Look at the permissions in the projects folder. One way:
ls -l projects - Try to run projects/hello.sh. It will be refused. One way:
./projects/hello.sh - Allow it to run. One way:
chmod +x projects/hello.sh - Run it again. One way:
./projects/hello.sh - See who owns the files in /etc. Owners and permissions decide who may change what. One way:
ls -l /etc
9. Break it safely
rm -rf / is the most feared command on Linux. Real systems have two safeguards against it, and here you can watch both work. Start it with /lesson 9.
- Try to delete everything. One way:
rm -rf / - rm refused. Tell it you really mean it. One way:
rm -rf --no-preserve-root / - See what survived. The system folders belong to root, so you could not delete them. One way:
ls / - Bring your files back. One way:
reset
10. AI for kids 1: meet the car data
Before an AI can learn anything, someone has to look at the data. You'll explore one drive of a car, second by second, the way OpenCarMind's model started. Start it with /lesson 10 or /ai.
- Go into the ai folder and list what is there. One way:
cd ai && ls - Read the plan. It lists all seven steps. One way:
cat README.txt - Look at the first five rows of the drive. The first row names the columns. One way:
head -n 5 drive.csv - Count the rows. One row is one second, plus the header. One way:
wc -l drive.csv - Count the seconds the driver was braking. The action column is the answer the AI must learn, called a label. One way:
grep -c brake drive.csv - Keep only the speed column, which is column 2. One way:
cut -d, -f2 drive.csv - Find the top speed: skip the header, keep the speed, sort the numbers, take the last one. One way:
tail -n +2 drive.csv | cut -d, -f2 | sort -n | tail -n 1 - The AI looks at 5 seconds at a time. Print the first 5-second window: rows 2 to 6. One way:
head -n 6 drive.csv | tail -n 5
11. AI for kids 2: windows and a teacher
Now the data becomes something a network can learn from. You'll cut the drive into 5-second windows with Python, then train a teacher network that guesses what the driver is doing. Start it with /lesson 11.
- Go into the ai folder and read windows.py. It is short. One way:
cd ~/ai && cat windows.py - Run it with Python. Python opens drive.csv in the folder you are in, so stay in ~/ai. One way:
python3 windows.py - Look at the first 3 lines of what it wrote. Each window is 4 numbers and the answer. One way:
head -n 3 windows.csv - Train the teacher. Watch the mistakes score go down as it learns. One way:
python3 teacher.py - Everything the teacher learned is a list of numbers. Look at them. One way:
cat teacher.txt
12. AI for kids 3: the teacher teaches a student
A car's chip is small, so the teacher is too big for it. In distillation a smaller student learns from the teacher's answers, including how sure the teacher was. Start it with /lesson 12.
- Go into ~/ai and read student.py. TEMPERATURE makes the teacher's answers softer. One way:
cd ~/ai && cat student.py - Run it and compare the student with the teacher. One way:
python3 student.py - Count the lines in both saved networks. One line is one row of numbers. One way:
wc -l teacher.txt student.txt
13. AI for kids 4: make it small
Two more tricks make the student fit a chip. Pruning sets tiny weights to zero. Quantization stores each weight as a whole number from -127 to 127 instead of a decimal. Start it with /lesson 13.
- In ~/ai, prune the student and see if it still gets the same answers right. One way:
cd ~/ai && python3 prune.py - Find the zeros it made. grep can count lines that hold 0.0000. One way:
grep -c 0.0000 pruned.txt - Quantize it. This writes model.h, the weights as C code. One way:
python3 quantize.py - Read model.h. Every weight is now a whole number. One way:
cat model.h
14. AI for kids 5: run it in C like the car
The car's chip runs C, not Python. You'll build a small C program with the 8-bit model inside and run it on the test windows. Start it with /lesson 14.
- Go into ~/ai and read car.c. It uses only whole numbers inside the network. One way:
cd ~/ai && less car.c - Build it. -o car names the program car. One way:
cc -o car car.c - Look at it with ls -l. The x in rwxr-xr-x means it can be run. One way:
ls -l car - Run it. The ./ means the car in this folder. One way:
./car - Show only the last line, the score. One way:
./car | tail -n 1
15. Quantum for kids: qubits you can see
A qubit can be part 0 and part 1 until you look. You'll run a small simulator and see the chances as bars, then read the same circuits in PennyLane. Start it with /lesson 15 or /quantum.
- Go into the quantum folder and list it. One way:
cd ~/quantum && ls - Run one qubit through a Hadamard gate and measure it 1000 times. One way:
python3 qubit.py - Make two qubits that always agree, a Bell pair. One way:
python3 bell.py - Turn a qubit a bit more each time and watch the bars grow. One way:
python3 rotate.py - Read the same Bell pair written with PennyLane. One way:
cat pennylane_bell.py - Try to run it. PennyLane isn't installed here, so read what Python says. One way:
python3 pennylane_bell.py
16. Processes and threads (/posix)
Every running program is a process with a number, its PID. You'll list processes, run one in the background, stop it, and build C programs that copy themselves and run threads. Start it with /lesson 16 or /posix.
- List the processes in this terminal. One way:
ps - $$ holds this shell's own PID. Print it. One way:
echo $$ - Start a job in the background with &. It waits 300 seconds while you carry on typing. One way:
sleep 300 & - List your jobs. One way:
jobs - See every process on the machine and who owns it. One way:
ps aux - Process 1100, worker, runs 4 threads. List them. One way:
ps -T -p 1100 - Stop your background job with a signal. One way:
kill %1 - Try to stop process 1, which belongs to root. One way:
kill 1 - Go into ~/posix, build threads.c and run it. One way:
cd ~/posix && cc -pthread -o threads threads.c && ./threads - Build and run fork.c, a program that copies itself. One way:
cc -o fork fork.c && ./fork
17. Networks (/ip)
This mode adds a small practice network inside the page: a router, a file server and a printer. You'll find your address, test who answers, look up names and fetch a web page. Start it with /lesson 17 or /ip.
- Find this machine's address. Look for inet under eth0. One way:
ip addr - See the route. Traffic for anywhere else goes via the router. One way:
ip route - Names on the practice network are listed in /etc/hosts. One way:
cat /etc/hosts - Check that the router answers. -c 3 sends three pings. One way:
ping -c 3 router.lan - Ask the name server for the file server's address. One way:
host files.lan - Fetch the file server's web page. One way:
curl http://files.lan/ - List the ports this machine listens on. 22 is SSH. One way:
ss -tln - Try to reach the internet. The practice router has no way out. One way:
ping -c 2 8.8.8.8
18. Real-time Linux (/rt)
A real-time task must run on time, every time. This mode runs a simulated PREEMPT_RT kernel. You'll check the kernel, learn the scheduling policies and measure wake-up delay with and without a real-time priority. Start it with /lesson 18 or /rt.
- Check the kernel. Look for PREEMPT_RT. One way:
uname -v - Real-time kernels also say so in this file. One way:
cat /sys/kernel/realtime - List the scheduling policies and their priority ranges. One way:
chrt -m - See which policy this shell runs with. One way:
chrt -p $$ - Your group may use real-time priorities up to this number. One way:
ulimit -r - Measure wake-up delay at normal priority. Note the Max column. One way:
cyclictest -m -i 1000 -l 10000 - Make the machine busy in the background. One way:
stress-ng --cpu 4 & - Measure again at normal priority, now that the machine is busy. One way:
cyclictest -m -i 1000 -l 10000 - Now measure with SCHED_FIFO priority 80. Compare Max. One way:
cyclictest -m -p 80 -i 1000 -l 10000 - Build the periodic task in ~/rt and run it at priority 80. One way:
cd ~/rt && cc -O2 -o cyclic cyclic.c && chrt -f 80 ./cyclic
AI for kids follows the steps behind OpenCarMind's on-board model, on a made-up drive in ~/ai/drive.csv: look at the data, cut it into 5-second windows, train a teacher network, distil it into a smaller student, prune it, store it as 8-bit numbers and run it from C. Online learning, which OpenCarMind also does, is left out. Quantum for kids simulates one and two qubits and shows the chances as bars, with the same circuits written in PennyLane.
The last three lessons are modes. A mode adds a topic and its tools, and the prompt starts with its name, like (rt) student@bfp:~$. In /posix you work with processes, signals, background jobs and threads. /ip adds a practice network that lives in the page: a router, a file server and a printer, and no way out to the internet. /rt switches to a simulated PREEMPT_RT kernel and puts you in the realtime group, so you may use real-time priorities up to 95. The page has no real timer, so cyclictest and cyclic.c print numbers from a model and say so. Run them on your own Linux machine to measure it. /mode off leaves a mode.
The browser page can't run Python or a C compiler, so python3 and cc here run built-in copies of the lesson scripts, written in TypeScript. Before each release we run the real python3 and cc on the same files and check that every line printed and every file written matches. cyclic.c measures real time, so for it we only check that it builds without warnings. A script only runs here as shipped. To change one and see what happens, download it below and run it on your own computer.
Files to run at home
These are the lesson files, byte for byte. Put the ai files in one folder and run them in order with Python 3, then build car.c with cc -o car car.c. They use only Python's standard library. The posix and rt files are C for Linux: build them with cc as each file's first comment shows. The two PennyLane files need pip install pennylane. We checked them with PennyLane 0.45.1 and they print the same chances as tiny_qsim.py.
| File | What it is |
|---|---|
ai/drive.csv | The made-up drive, one row per second. |
ai/windows.py | Step 2: cuts the drive into 5-second windows and writes windows.csv. |
ai/tiny_nn.py | The neural network itself, in plain Python with no libraries. |
ai/teacher.py | Step 3: trains the teacher network and writes teacher.txt. |
ai/student.py | Step 4: distillation, a smaller student learns from the teacher. Writes student.txt. |
ai/prune.py | Step 5: sets weights near zero to zero. Writes pruned.txt. |
ai/quantize.py | Step 6: turns the weights into 8-bit whole numbers. Writes model.h. |
ai/car.c | Step 7: the C program that runs the 8-bit model, built with model.h. |
quantum/tiny_qsim.py | The quantum simulator: a list of amplitudes and a few gates. |
quantum/qubit.py | One qubit through a Hadamard gate, measured 1000 times. |
quantum/bell.py | Two entangled qubits, a Bell pair. |
quantum/rotate.py | Turns a qubit step by step and draws the chance of 1. |
quantum/pennylane_bell.py | The Bell pair in PennyLane. |
quantum/pennylane_rotate.py | The turning qubit in PennyLane. |
posix/fork.c | A process copies itself with fork() and waits for the child. |
posix/threads.c | Four POSIX threads share a sum, then a counter guarded by a mutex. |
rt/cyclic.c | A 1 ms periodic task that measures its wake-up delay. Try it with chrt -f 80. |
Slash commands
These belong to the terminal itself, not to Linux.
| Type | What it does |
|---|---|
/lessons | show the lessons |
/lesson N | start lesson N |
/ai | start AI for kids |
/quantum | start Quantum for kids |
/posix | processes and threads mode |
/ip | practice network mode |
/rt | real-time Linux mode |
/mode | show the mode. /mode off leaves it |
/hint | show the hint for this step |
/skip | skip this step |
/reset | put every file back |
/privacy | what this page keeps |
/clear | clear the screen |
Shortcuts: Tab completes, Up and Down walk your history, Ctrl+L clears, Ctrl+C drops the line.
Commands
67 commands work, with pipes (|), redirects (>, >>, <), &&, ||, ;, quotes, variables and wildcards. Type man NAME in the terminal for the same help.
| Command | Usage | What it does |
|---|---|---|
apt | apt install PACKAGE | install software. Needs root |
bg | bg [%N] | let a stopped job carry on in the background |
cat | cat FILE... | print files, one after another |
cc | cc -o NAME FILE.c | build a C program (here: the lesson's car.c) |
cd | cd [PATH] | change folder. cd .. goes up, cd ~ goes home |
chmod | chmod MODE FILE | change permissions, like 755 or +x. Only a file's owner may |
chrt | chrt -m | chrt -p PID | chrt [-f|-r] PRIO COMMAND | see or set real-time scheduling |
clear | clear | clear the screen (Ctrl+L does it too) |
cp | cp [-r] SRC DEST | copy a file, or a folder with -r |
curl | curl [-I] [-o FILE] URL | fetch a web page, like curl http://files.lan/ (in /ip mode) |
cut | cut -d DELIM -f LIST [FILE] | keep some columns, like cut -d, -f2 for the second comma-separated one |
cyclictest | cyclictest [-m] [-p PRIO] [-i US] [-l LOOPS] [-S] | measure timer wake-up delay (in /rt mode, simulated) |
date | date | print the date and time |
echo | echo TEXT | print text. Use > to write it to a file |
env | env | list variables. UID and EUID are read-only |
exit | exit | close the shell (here it stays open) |
export | export NAME=VALUE | set a variable. Read it with $NAME |
fg | fg [%N] | bring a background job to the front |
find | find [PATH] [-name PATTERN] [-type f|d] | search for files |
gcc | gcc -o NAME FILE.c | the GNU C compiler, same as cc |
grep | grep [-i] [-n] [-v] [-c] PATTERN [FILE] | find lines that match |
groups | groups | print the groups you belong to |
head | head [-n N] FILE | first N lines (10 by default) |
history | history | list the commands you typed |
host | host NAME | look up a name's address (in /ip mode) |
hostname | hostname | print the machine name |
id | id | print your user id, group and groups |
ip | ip addr|route|link|neigh | show the network (in /ip mode) |
jobs | jobs | list the jobs you started with & |
kill | kill [-SIGNAL] PID|%JOB | send a signal. TERM by default, -9 is KILL. kill -l lists signals |
less | less FILE | read a file one screen at a time (here it prints all of it) |
logout | logout | same as exit |
ls | ls [-l] [-a] [PATH] | list files. -l shows details, -a shows hidden files and the . and .. folders |
man | man COMMAND | show help for a command |
mkdir | mkdir [-p] [-v] DIR... | make folders. -p makes parent folders too, -v says what it made |
more | more FILE | an older pager, like less |
mv | mv SRC DEST | move or rename |
nproc | nproc | print the number of CPUs |
nslookup | nslookup NAME | look up a name, showing which server answered (in /ip mode) |
ping | ping [-c N] HOST | check that a machine answers (in /ip mode) |
pip | pip install PACKAGE | install a Python package. Needs the internet, which this page doesn't have |
ps | ps [-e] [-f] [aux] [-T] [-p PID] [-o COLUMNS] | list processes. -e or aux shows everyone's, -T shows threads |
pstree | pstree | draw the processes as a family tree |
pwd | pwd | print the folder you are in |
python3 | python3 FILE | run a Python script (here: the AI for kids and quantum lesson scripts) |
reset | reset | put every file back the way it started |
rm | rm [-r] [-f] PATH | delete. -r deletes folders and what is inside. rm refuses / unless you add --no-preserve-root |
rmdir | rmdir DIR | delete an empty folder |
sh | sh FILE | run a script, one command per line |
sleep | sleep SECONDS | wait. Add & to wait in the background (here a foreground sleep ends at once) |
sort | sort [-r] [-n] [FILE] | sort lines |
ss | ss -tln | list the ports this machine listens on (in /ip mode) |
stress-ng | stress-ng --cpu N [--timeout S] | keep the CPUs busy, usually with & (in /rt mode) |
su | su [USER] | switch user. Needs that user's password, which you do not have here |
sudo | sudo COMMAND | run as administrator. Only members of the sudo group may, and student is not one |
tail | tail [-n N] FILE | last N lines (10 by default). -n +N starts at line N |
top | top | a snapshot of the busiest processes |
touch | touch FILE | make an empty file, or update its time |
traceroute | traceroute HOST | show each hop on the way to a machine (in /ip mode) |
tree | tree [-a] [PATH] | draw a folder as a tree. -a shows hidden files too |
ulimit | ulimit [-a] [-r] [-l] | show your limits. -r is the highest real-time priority you may use |
uname | uname [-a] | print system information |
uniq | uniq [-c] [FILE] | drop repeated neighbouring lines. Sort first |
wait | wait | wait for your background jobs to finish |
wc | wc [-l] [-w] [-c] FILE | count lines, words and characters |
which | which COMMAND | show where a command lives |
whoami | whoami | print your user name. Changing $USER does not change who you are |
Who you are
You are the ordinary user student (uid 1000), and you aren't in the sudo group. Your home folder /home/student and /tmp are yours. The rest of the system belongs to root, as on a shared server:
- You can read most system files, such as
/etc/passwdand/var/log/app.log, but not change them. /etc/shadow,/etc/sudoers,/rootand/var/log/auth.logare for root only and answer "Permission denied".sudoandsurefuse, andUIDandEUIDcan't be changed. Setting$USERdoesn't change who you are.rm -rf /refuses unless you add--no-preserve-root, and even then it deletes only your own files.resetbrings them back.
What isn't there
This is a teaching shell written for this site, not a full Linux. There are no editors such as vim and no package manager, the network tools only reach the practice network in /ip mode, background jobs are limited to sleep and stress-ng, and command substitution like $(whoami) isn't supported. python3 and cc only run the lesson files, as explained under Lessons. Files live in the page's memory, so reloading the page starts fresh. When you want the real thing, WebTerm and a Linux machine of your own are good next steps.