Command cheat sheet
Moving around
| Command | Does |
|---|---|
pwd | Where am I? |
ls / ls -la | List files / with details and hidden files |
cd folder / cd .. / cd ~ | Go into / up one / home |
tree -L 2 | Folder tree (install with sudo apt install tree) |
Files
| Command | Does |
|---|---|
cat file | Print a file |
less file | Scroll through a file (q to quit, / to search) |
head -n 20 file / tail -n 20 file | First / last 20 lines |
tail -f file | Follow a growing file (logs) |
nano file | Edit |
cp -a a b / mv a b / rm file | Copy (keeping owners) / move or rename / delete |
mkdir -p a/b/c | Make folders |
touch file | Create an empty file |
file name | What kind of file is it? |
Finding things
| Command | Does |
|---|---|
grep -rn "Nypuser" /home/pi | Find text in files (with line numbers) |
grep -i error file | Case-insensitive |
find / -name "apache2.conf" 2>/dev/null | Find a file by name |
which python | Which program runs for a command |
history | grep apt | Commands you typed before |
System and hardware
| Command | Does |
|---|---|
cat /etc/os-release | OS version (Bookworm = Debian 12) |
uname -a | Kernel version |
date / timedatectl | Time, time zone, sync status |
uptime | How long since boot, load |
free -h | Memory |
df -h | Disk (card) space |
du -sh * | Size of each item here |
lsblk | Disks and partitions |
lsusb | USB devices (Arduino, keyboard) |
vcgencmd measure_temp | CPU temperature |
vcgencmd get_throttled | Power problems since boot (0x0 = none) |
pinout | GPIO header map |
Processes
| Command | Does |
|---|---|
ps aux | grep python | Find running Python programs |
pgrep -a python | Same, shorter |
kill 1234 / kill -9 1234 | Stop process 1234 / force it |
top / htop | Live view of CPU and memory (q to quit) |
sudo fuser -v /dev/ttyACM0 | Who is using the serial port |
sudo fuser -k 5000/tcp | Kill whatever uses port 5000 |
Services and logs
| Command | Does |
|---|---|
systemctl status apache2 | Running? Last log lines |
sudo systemctl restart apache2 | Restart |
sudo journalctl -u mariadb -n 50 | Last 50 log lines |
sudo apache2ctl configtest | Check Apache config |
sudo tail /var/log/apache2/error.log | Apache/PHP errors |
sudo dmesg | tail | Kernel messages (USB plug-ins, card errors) |
Network
| Command | Does |
|---|---|
hostname -I | My IP |
ip -br addr | All interfaces, short |
ping -c 3 google.com | Reachable? |
sudo ss -tlnp | Who listens on which port |
curl -I http://localhost | Test a web server |
ssh pi@IP / scp file pi@IP:~/ | Remote terminal / copy file |
Packages
| Command | Does |
|---|---|
sudo apt update && sudo apt upgrade -y | Update everything |
sudo apt install NAME | Install |
sudo apt purge NAME | Remove with config |
sudo dpkg --configure -a | Repair interrupted installs |
sudo dpkg-reconfigure NAME | Answer setup questions again |
Combining commands
| Syntax | Does |
|---|---|
a | b | Send a's output into b |
a > file | Output into a file (overwrites) |
a >> file | Append to a file |
a 2>&1 | Errors to the same place as output |
a && b | Run b only if a succeeded |
a ; b | Run both, whatever happens |
a & | Run in the background |