BuildForPeople

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.

  1. Print your working directory. One way: pwd
  2. Go to the very top of the file system, the root folder called /. One way: cd /
  3. Go into home with a relative path, one with no slash in front. One way: cd home
  4. Go back up one level. Two dots mean the folder above. One way: cd ..
  5. Jump straight to the log folder with an absolute path. One way: cd /var/log
  6. Ask the terminal who you are. One way: whoami
  7. Go home. cd on its own, or cd ~, always takes you there. One way: cd ~
  8. 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.

  1. Make a folder called practice inside /tmp. One way: mkdir /tmp/practice
  2. Go into it. One way: cd /tmp/practice
  3. Make three folders with one command: red, green and blue. One way: mkdir red green blue
  4. Make one/two/three in one go. The -p option makes the folders in between. One way: mkdir -p one/two/three
  5. Make a folder whose name has a space. Quotes keep the name in one piece. One way: mkdir "my notes"
  6. Write a line into note_1.txt with echo and >. One way: echo "first note" > note_1.txt
  7. 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
  8. Print all three with a wildcard. ? stands for any one character. One way: cat note_?.txt
  9. 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
  10. 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.

  1. Go to /tmp/practice and move all.txt into the red folder. One way: cd /tmp/practice && mv all.txt red
  2. Bring everything in red back here. A single dot means the folder you are in. One way: mv red/* .
  3. Move several files at once. The last name is where they all go. One way: mv all.txt note_* green
  4. Copy all.txt from green back here. One way: cp green/all.txt .
  5. Rename by moving: call the copy backup.txt. One way: mv all.txt backup.txt
  6. Spaces in names are a pain to type. Rename "my notes" to my_notes. One way: mv "my notes" my_notes
  7. Delete backup.txt. It is gone for good. One way: rm backup.txt
  8. Delete the empty blue folder with rmdir. One way: rmdir blue
  9. 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.

  1. Count the lines in your fruit list. One way: wc -l ~/notes/fruits.txt
  2. Count the things in your home folder by piping ls into wc. One way: ls ~ | wc -l
  3. 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
  4. Sort first, so the repeats sit together, then uniq keeps one of each. One way: sort ~/notes/fruits.txt | uniq
  5. Count how many different fruits there are. One way: sort ~/notes/fruits.txt | uniq | wc -l
  6. 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.

  1. Try to read /etc/shadow, where password hashes are kept. One way: cat /etc/shadow
  2. On your own machine you would put sudo in front. Try it. One way: sudo cat /etc/shadow
  3. See why it refused: list your groups. Only members of the sudo group may use sudo. One way: id
  4. Try to install a program with apt, Ubuntu's package manager. One way: apt install tree
  5. 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.

  1. Go to /tmp/practice. One way: cd /tmp/practice
  2. Hide b.txt by giving it a name that starts with a dot. One way: mv b.txt .b.txt
  3. List the folder. The hidden file doesn't show. One way: ls
  4. Now list with -a. You'll also see . (this folder) and .. (the one above). One way: ls -a
  5. Make a hidden folder called .secret and move the hidden file into it. One way: mkdir .secret && mv .b.txt .secret
  6. tree hides dot names too, until you add -a. One way: tree -a
  7. Count everything in your home folder, hidden files included. One way: ls -a ~ | wc -l
  8. Clean up after yourself: delete the whole practice folder. One way: rm -r /tmp/practice

grep finds lines that match a pattern. It is how people dig through logs. Start it with /lesson 7.

  1. Show the lines with ERROR in /var/log/app.log. One way: grep ERROR /var/log/app.log
  2. Do the same, with line numbers. One way: grep -n ERROR /var/log/app.log
  3. Find the lines that mention login, whatever the case. One way: grep -i LOGIN /var/log/app.log
  4. Show the last 3 lines of the log. One way: tail -n 3 /var/log/app.log
  5. 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.

  1. Look at the permissions in the projects folder. One way: ls -l projects
  2. Try to run projects/hello.sh. It will be refused. One way: ./projects/hello.sh
  3. Allow it to run. One way: chmod +x projects/hello.sh
  4. Run it again. One way: ./projects/hello.sh
  5. 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.

  1. Try to delete everything. One way: rm -rf /
  2. rm refused. Tell it you really mean it. One way: rm -rf --no-preserve-root /
  3. See what survived. The system folders belong to root, so you could not delete them. One way: ls /
  4. 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.

  1. Go into the ai folder and list what is there. One way: cd ai && ls
  2. Read the plan. It lists all seven steps. One way: cat README.txt
  3. Look at the first five rows of the drive. The first row names the columns. One way: head -n 5 drive.csv
  4. Count the rows. One row is one second, plus the header. One way: wc -l drive.csv
  5. 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
  6. Keep only the speed column, which is column 2. One way: cut -d, -f2 drive.csv
  7. 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
  8. 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.

  1. Go into the ai folder and read windows.py. It is short. One way: cd ~/ai && cat windows.py
  2. Run it with Python. Python opens drive.csv in the folder you are in, so stay in ~/ai. One way: python3 windows.py
  3. 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
  4. Train the teacher. Watch the mistakes score go down as it learns. One way: python3 teacher.py
  5. 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.

  1. Go into ~/ai and read student.py. TEMPERATURE makes the teacher's answers softer. One way: cd ~/ai && cat student.py
  2. Run it and compare the student with the teacher. One way: python3 student.py
  3. 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.

  1. In ~/ai, prune the student and see if it still gets the same answers right. One way: cd ~/ai && python3 prune.py
  2. Find the zeros it made. grep can count lines that hold 0.0000. One way: grep -c 0.0000 pruned.txt
  3. Quantize it. This writes model.h, the weights as C code. One way: python3 quantize.py
  4. 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.

  1. Go into ~/ai and read car.c. It uses only whole numbers inside the network. One way: cd ~/ai && less car.c
  2. Build it. -o car names the program car. One way: cc -o car car.c
  3. Look at it with ls -l. The x in rwxr-xr-x means it can be run. One way: ls -l car
  4. Run it. The ./ means the car in this folder. One way: ./car
  5. 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.

  1. Go into the quantum folder and list it. One way: cd ~/quantum && ls
  2. Run one qubit through a Hadamard gate and measure it 1000 times. One way: python3 qubit.py
  3. Make two qubits that always agree, a Bell pair. One way: python3 bell.py
  4. Turn a qubit a bit more each time and watch the bars grow. One way: python3 rotate.py
  5. Read the same Bell pair written with PennyLane. One way: cat pennylane_bell.py
  6. 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.

  1. List the processes in this terminal. One way: ps
  2. $$ holds this shell's own PID. Print it. One way: echo $$
  3. Start a job in the background with &. It waits 300 seconds while you carry on typing. One way: sleep 300 &
  4. List your jobs. One way: jobs
  5. See every process on the machine and who owns it. One way: ps aux
  6. Process 1100, worker, runs 4 threads. List them. One way: ps -T -p 1100
  7. Stop your background job with a signal. One way: kill %1
  8. Try to stop process 1, which belongs to root. One way: kill 1
  9. Go into ~/posix, build threads.c and run it. One way: cd ~/posix && cc -pthread -o threads threads.c && ./threads
  10. 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.

  1. Find this machine's address. Look for inet under eth0. One way: ip addr
  2. See the route. Traffic for anywhere else goes via the router. One way: ip route
  3. Names on the practice network are listed in /etc/hosts. One way: cat /etc/hosts
  4. Check that the router answers. -c 3 sends three pings. One way: ping -c 3 router.lan
  5. Ask the name server for the file server's address. One way: host files.lan
  6. Fetch the file server's web page. One way: curl http://files.lan/
  7. List the ports this machine listens on. 22 is SSH. One way: ss -tln
  8. 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.

  1. Check the kernel. Look for PREEMPT_RT. One way: uname -v
  2. Real-time kernels also say so in this file. One way: cat /sys/kernel/realtime
  3. List the scheduling policies and their priority ranges. One way: chrt -m
  4. See which policy this shell runs with. One way: chrt -p $$
  5. Your group may use real-time priorities up to this number. One way: ulimit -r
  6. Measure wake-up delay at normal priority. Note the Max column. One way: cyclictest -m -i 1000 -l 10000
  7. Make the machine busy in the background. One way: stress-ng --cpu 4 &
  8. Measure again at normal priority, now that the machine is busy. One way: cyclictest -m -i 1000 -l 10000
  9. Now measure with SCHED_FIFO priority 80. Compare Max. One way: cyclictest -m -p 80 -i 1000 -l 10000
  10. 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.

AI for kids and Quantum for kids lesson files
FileWhat it is
ai/drive.csvThe made-up drive, one row per second.
ai/windows.pyStep 2: cuts the drive into 5-second windows and writes windows.csv.
ai/tiny_nn.pyThe neural network itself, in plain Python with no libraries.
ai/teacher.pyStep 3: trains the teacher network and writes teacher.txt.
ai/student.pyStep 4: distillation, a smaller student learns from the teacher. Writes student.txt.
ai/prune.pyStep 5: sets weights near zero to zero. Writes pruned.txt.
ai/quantize.pyStep 6: turns the weights into 8-bit whole numbers. Writes model.h.
ai/car.cStep 7: the C program that runs the 8-bit model, built with model.h.
quantum/tiny_qsim.pyThe quantum simulator: a list of amplitudes and a few gates.
quantum/qubit.pyOne qubit through a Hadamard gate, measured 1000 times.
quantum/bell.pyTwo entangled qubits, a Bell pair.
quantum/rotate.pyTurns a qubit step by step and draws the chance of 1.
quantum/pennylane_bell.pyThe Bell pair in PennyLane.
quantum/pennylane_rotate.pyThe turning qubit in PennyLane.
posix/fork.cA process copies itself with fork() and waits for the child.
posix/threads.cFour POSIX threads share a sum, then a counter guarded by a mutex.
rt/cyclic.cA 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.

TypeWhat it does
/lessonsshow the lessons
/lesson Nstart lesson N
/aistart AI for kids
/quantumstart Quantum for kids
/posixprocesses and threads mode
/ippractice network mode
/rtreal-time Linux mode
/modeshow the mode. /mode off leaves it
/hintshow the hint for this step
/skipskip this step
/resetput every file back
/privacywhat this page keeps
/clearclear 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.

CommandUsageWhat it does
aptapt install PACKAGEinstall software. Needs root
bgbg [%N]let a stopped job carry on in the background
catcat FILE...print files, one after another
cccc -o NAME FILE.cbuild a C program (here: the lesson's car.c)
cdcd [PATH]change folder. cd .. goes up, cd ~ goes home
chmodchmod MODE FILEchange permissions, like 755 or +x. Only a file's owner may
chrtchrt -m | chrt -p PID | chrt [-f|-r] PRIO COMMANDsee or set real-time scheduling
clearclearclear the screen (Ctrl+L does it too)
cpcp [-r] SRC DESTcopy a file, or a folder with -r
curlcurl [-I] [-o FILE] URLfetch a web page, like curl http://files.lan/ (in /ip mode)
cutcut -d DELIM -f LIST [FILE]keep some columns, like cut -d, -f2 for the second comma-separated one
cyclictestcyclictest [-m] [-p PRIO] [-i US] [-l LOOPS] [-S]measure timer wake-up delay (in /rt mode, simulated)
datedateprint the date and time
echoecho TEXTprint text. Use > to write it to a file
envenvlist variables. UID and EUID are read-only
exitexitclose the shell (here it stays open)
exportexport NAME=VALUEset a variable. Read it with $NAME
fgfg [%N]bring a background job to the front
findfind [PATH] [-name PATTERN] [-type f|d]search for files
gccgcc -o NAME FILE.cthe GNU C compiler, same as cc
grepgrep [-i] [-n] [-v] [-c] PATTERN [FILE]find lines that match
groupsgroupsprint the groups you belong to
headhead [-n N] FILEfirst N lines (10 by default)
historyhistorylist the commands you typed
hosthost NAMElook up a name's address (in /ip mode)
hostnamehostnameprint the machine name
ididprint your user id, group and groups
ipip addr|route|link|neighshow the network (in /ip mode)
jobsjobslist the jobs you started with &
killkill [-SIGNAL] PID|%JOBsend a signal. TERM by default, -9 is KILL. kill -l lists signals
lessless FILEread a file one screen at a time (here it prints all of it)
logoutlogoutsame as exit
lsls [-l] [-a] [PATH]list files. -l shows details, -a shows hidden files and the . and .. folders
manman COMMANDshow help for a command
mkdirmkdir [-p] [-v] DIR...make folders. -p makes parent folders too, -v says what it made
moremore FILEan older pager, like less
mvmv SRC DESTmove or rename
nprocnprocprint the number of CPUs
nslookupnslookup NAMElook up a name, showing which server answered (in /ip mode)
pingping [-c N] HOSTcheck that a machine answers (in /ip mode)
pippip install PACKAGEinstall a Python package. Needs the internet, which this page doesn't have
psps [-e] [-f] [aux] [-T] [-p PID] [-o COLUMNS]list processes. -e or aux shows everyone's, -T shows threads
pstreepstreedraw the processes as a family tree
pwdpwdprint the folder you are in
python3python3 FILErun a Python script (here: the AI for kids and quantum lesson scripts)
resetresetput every file back the way it started
rmrm [-r] [-f] PATHdelete. -r deletes folders and what is inside. rm refuses / unless you add --no-preserve-root
rmdirrmdir DIRdelete an empty folder
shsh FILErun a script, one command per line
sleepsleep SECONDSwait. Add & to wait in the background (here a foreground sleep ends at once)
sortsort [-r] [-n] [FILE]sort lines
ssss -tlnlist the ports this machine listens on (in /ip mode)
stress-ngstress-ng --cpu N [--timeout S]keep the CPUs busy, usually with & (in /rt mode)
susu [USER]switch user. Needs that user's password, which you do not have here
sudosudo COMMANDrun as administrator. Only members of the sudo group may, and student is not one
tailtail [-n N] FILElast N lines (10 by default). -n +N starts at line N
toptopa snapshot of the busiest processes
touchtouch FILEmake an empty file, or update its time
traceroutetraceroute HOSTshow each hop on the way to a machine (in /ip mode)
treetree [-a] [PATH]draw a folder as a tree. -a shows hidden files too
ulimitulimit [-a] [-r] [-l]show your limits. -r is the highest real-time priority you may use
unameuname [-a]print system information
uniquniq [-c] [FILE]drop repeated neighbouring lines. Sort first
waitwaitwait for your background jobs to finish
wcwc [-l] [-w] [-c] FILEcount lines, words and characters
whichwhich COMMANDshow where a command lives
whoamiwhoamiprint 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/passwd and /var/log/app.log, but not change them.
  • /etc/shadow, /etc/sudoers, /root and /var/log/auth.log are for root only and answer "Permission denied".
  • sudo and su refuse, and UID and EUID can't be changed. Setting $USER doesn't change who you are.
  • rm -rf / refuses unless you add --no-preserve-root, and even then it deletes only your own files. reset brings 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.