Skip to main content

Command cheat sheet

Moving around​

CommandDoes
pwdWhere am I?
ls / ls -laList files / with details and hidden files
cd folder / cd .. / cd ~Go into / up one / home
tree -L 2Folder tree (install with sudo apt install tree)

Files​

CommandDoes
cat filePrint a file
less fileScroll through a file (q to quit, / to search)
head -n 20 file / tail -n 20 fileFirst / last 20 lines
tail -f fileFollow a growing file (logs)
nano fileEdit
cp -a a b / mv a b / rm fileCopy (keeping owners) / move or rename / delete
mkdir -p a/b/cMake folders
touch fileCreate an empty file
file nameWhat kind of file is it?

Finding things​

CommandDoes
grep -rn "Nypuser" /home/piFind text in files (with line numbers)
grep -i error fileCase-insensitive
find / -name "apache2.conf" 2>/dev/nullFind a file by name
which pythonWhich program runs for a command
history | grep aptCommands you typed before

System and hardware​

CommandDoes
cat /etc/os-releaseOS version (Bookworm = Debian 12)
uname -aKernel version
date / timedatectlTime, time zone, sync status
uptimeHow long since boot, load
free -hMemory
df -hDisk (card) space
du -sh *Size of each item here
lsblkDisks and partitions
lsusbUSB devices (Arduino, keyboard)
vcgencmd measure_tempCPU temperature
vcgencmd get_throttledPower problems since boot (0x0 = none)
pinoutGPIO header map

Processes​

CommandDoes
ps aux | grep pythonFind running Python programs
pgrep -a pythonSame, shorter
kill 1234 / kill -9 1234Stop process 1234 / force it
top / htopLive view of CPU and memory (q to quit)
sudo fuser -v /dev/ttyACM0Who is using the serial port
sudo fuser -k 5000/tcpKill whatever uses port 5000

Services and logs​

CommandDoes
systemctl status apache2Running? Last log lines
sudo systemctl restart apache2Restart
sudo journalctl -u mariadb -n 50Last 50 log lines
sudo apache2ctl configtestCheck Apache config
sudo tail /var/log/apache2/error.logApache/PHP errors
sudo dmesg | tailKernel messages (USB plug-ins, card errors)

Network​

CommandDoes
hostname -IMy IP
ip -br addrAll interfaces, short
ping -c 3 google.comReachable?
sudo ss -tlnpWho listens on which port
curl -I http://localhostTest a web server
ssh pi@IP / scp file pi@IP:~/Remote terminal / copy file

Packages​

CommandDoes
sudo apt update && sudo apt upgrade -yUpdate everything
sudo apt install NAMEInstall
sudo apt purge NAMERemove with config
sudo dpkg --configure -aRepair interrupted installs
sudo dpkg-reconfigure NAMEAnswer setup questions again

Combining commands​

SyntaxDoes
a | bSend a's output into b
a > fileOutput into a file (overwrites)
a >> fileAppend to a file
a 2>&1Errors to the same place as output
a && bRun b only if a succeeded
a ; bRun both, whatever happens
a &Run in the background