Skip to main content

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:~ $
PartMeaning
piYou are logged in as user pi
raspberrypiThe computer's name (hostname)
~Current folder. ~ = your home, /home/pi
$Normal user. # means root (careful)
(env) in frontThe Python venv is active

The file system​

Linux has one tree starting at / (no C: or D: drives). The folders you will meet:

FolderWhat is in it
/home/piYour files, your venv, your Python scripts
/etcSystem-wide config files (/etc/apache2, /etc/mysql)
/var/www/htmlApache's web pages
/var/lib/mysqlMariaDB's databases (do not edit by hand)
/var/logLog files
/devDevices as files: /dev/ttyACM0 (Arduino), /dev/mmcblk0 (the SD card)
/boot/firmwareBoot files on the card's small FAT partition (config.txt, cmdline.txt)
/tmpTemporary files; do not keep work here

Paths​

  • Absolute paths start with /: /home/pi/app.py works 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, LS is not a command.
  • Spaces separate arguments. A file called my file.py must be typed as "my file.py" or my\ 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 with ls -a.

Keyboard shortcuts that save time​

KeysDoes
TabCompletes file and command names. Press twice to list options. If Tab does not complete, the file is not there.
↑ / ↓Previous commands
Ctrl+RSearch previous commands (type part of it)
Ctrl+CStop the running program
Ctrl+DLog out / end input
Ctrl+LClear the screen
Ctrl+Shift+C / VCopy / paste in the terminal
!!The last command again (sudo !! = last command with sudo)

Stuck in a program?​

You are inLeave with
less, man, systemctl statusq
nanoCtrl+X (then Y/N to save)
vi / vim (opened by accident)Esc, then type :q! and Enter
A running scriptCtrl+C
MariaDB (MariaDB [...]>)exit
Python (>>>)exit() or Ctrl+D
A prompt that shows > and waitsYou 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)