Linux basics
Raspberry Pi OS is Debian Linux. The lab sheets tell you which commands to type; this page is about reading what Linux tells you back, so you can work out the rest yourself.
Reading the prompt
pi@raspberrypi:~ $
| Part | Meaning |
|---|---|
pi | You are logged in as user pi |
raspberrypi | The computer's name (hostname) |
~ | Current folder. ~ = your home, /home/pi |
$ | Normal user. # means root (careful) |
(env) in front | The Python venv is active |
The file system
Linux has one tree starting at / (no C: or D: drives). The folders you will meet:
| Folder | What is in it |
|---|---|
/home/pi | Your files, your venv, your Python scripts |
/etc | System-wide config files (/etc/apache2, /etc/mysql) |
/var/www/html | Apache's web pages |
/var/lib/mysql | MariaDB's databases (do not edit by hand) |
/var/log | Log files |
/dev | Devices as files: /dev/ttyACM0 (Arduino), /dev/mmcblk0 (the SD card) |
/boot/firmware | Boot files on the card's small FAT partition (config.txt, cmdline.txt) |
/tmp | Temporary files; do not keep work here |
Paths
- Absolute paths start with
/:/home/pi/app.pyworks from anywhere. - Relative paths start from where you are:
templates/index.html,../(one folder up),./(here). ~is your home folder.
No such file or directory very often means you are in a different folder than you think. Check with pwd, and use absolute paths in scripts and config files.
Rules that catch beginners
- Everything is case-sensitive:
Templates≠templates,MySensor≠mysensor,LSis not a command. - Spaces separate arguments. A file called
my file.pymust be typed as"my file.py"ormy\ file.py. Avoid spaces in names. - No news is good news. Most commands print nothing when they succeed.
- File extensions mean nothing to Linux. A file is a script because of what is in it, not because it ends in
.py. - Hidden files start with a dot (
.bashrc,.ssh). See them withls -a.
Keyboard shortcuts that save time
| Keys | Does |
|---|---|
| Tab | Completes file and command names. Press twice to list options. If Tab does not complete, the file is not there. |
| ↑ / ↓ | Previous commands |
| Ctrl+R | Search previous commands (type part of it) |
| Ctrl+C | Stop the running program |
| Ctrl+D | Log out / end input |
| Ctrl+L | Clear the screen |
| Ctrl+Shift+C / V | Copy / paste in the terminal |
!! | The last command again (sudo !! = last command with sudo) |
Stuck in a program?
| You are in | Leave with |
|---|---|
less, man, systemctl status | q |
nano | Ctrl+X (then Y/N to save) |
vi / vim (opened by accident) | Esc, then type :q! and Enter |
| A running script | Ctrl+C |
MariaDB (MariaDB [...]>) | exit |
Python (>>>) | exit() or Ctrl+D |
A prompt that shows > and waits | You opened a quote or bracket. Ctrl+C |
Getting help
man ls # the manual (q to quit, / to search)
ls --help # short help for most commands
type ll # what a command really is (alias, program, built-in)