This article covers the most useful command line tricks for Raspberry Pi owners, from basic system monitoring to advanced network and storage tasks. You’ll learn the exact commands to check temperature, overclock safely, manage services, and automate backups, so you can get more from your Pi without a graphical desktop.
Why the Command Line Matters on a Raspberry Pi
The Raspberry Pi is a full Linux computer, but its limited RAM and CPU mean a lightweight setup without a desktop environment often runs faster and more reliably. The command line (shell) gives you direct control over every part of the system, uses fewer resources, and makes remote administration over SSH much simpler. Many official Raspberry Pi OS images now boot to the command line by default, and most headless projects (servers, home automation, network tools) never need a screen at all.
Essential System Monitoring Commands
Knowing what your Pi is doing at any moment helps you catch problems before they cause crashes. These commands are safe to run at any time and give you a snapshot of CPU, memory, disk, and temperature.
vcgencmd measure_temp– shows the CPU temperature in degrees Celsius. On a Raspberry Pi 4, idle temperatures around 45–55°C are normal; under load it can reach 80°C before throttling kicks in.vcgencmd measure_volts core– displays the core voltage, useful when checking if your power supply is adequate (should be around 0.8–0.9V idle, higher under load).vcgencmd get_throttled– returns a hexadecimal value that tells you if the Pi has experienced undervoltage or thermal throttling. A value of0x0means all is well;0x50000indicates throttling has occurred since boot.htop– an interactive process viewer (install withsudo apt install htop) that shows CPU cores, memory usage, and running processes in real time.df -h– shows disk space usage in human-readable format (e.g.,29Gused out of32G).free -h– displays RAM usage, including swap.
For a one-line overview, you can combine commands: echo "CPU temp: $(vcgencmd measure_temp | cut -d= -f2)".
Safe Overclocking and Performance Tuning
Overclocking a Raspberry Pi can improve performance, but it increases heat and power draw. The official Raspberry Pi OS includes a configuration tool that makes it relatively safe because it sets conservative limits and enables throttling.
- Run
sudo raspi-configand select Performance Options → Overclock. - Choose a preset (e.g., Pi 4: 2.0 GHz). The tool automatically sets the appropriate
arm_freqandover_voltagevalues in/boot/config.txt. - Reboot with
sudo reboot. - Check stability by running
vcgencmd measure_tempunder load (e.g.,stress --cpu 4). If the temperature exceeds 85°C, revert to the default clock.
For manual control, edit /boot/config.txt (on newer OS versions, it’s /boot/firmware/config.txt) and add lines like arm_freq=2000 and over_voltage=6. Always test with a known workload and monitor temperatures. The Pi’s firmware automatically throttles the CPU when it reaches 85°C, so a crash usually means your overclock is too aggressive—reduce the frequency.
Managing Services with systemctl
Most Raspberry Pi projects run background services (web servers, MQTT brokers, custom Python scripts). The systemctl command is the standard way to control them.
sudo systemctl status my-service– shows whether the service is running, its PID, and recent log lines.sudo systemctl start my-service/stop/restart– start, stop, or restart a service.sudo systemctl enable my-service– makes the service start automatically at boot.sudo systemctl disable my-service– stops it from starting at boot.journalctl -u my-service -f– follows the service’s log output in real time, which is invaluable for debugging.
To create your own service, write a unit file in /etc/systemd/system/. For example, my-script.service might contain:
[Unit]
Description=My Python Script
After=network.target
[Service]
ExecStart=/usr/bin/python3 /home/pi/script.py
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
Then run sudo systemctl daemon-reload and sudo systemctl enable --now my-script.
Network and Remote Access Tricks
Working headless (without a monitor) is common, so knowing how to find and connect to your Pi on the network is essential.
hostname -I– shows the Pi’s IP address(es).sudo apt install avahi-daemon– enables mDNS, so you can reach the Pi atraspberrypi.localinstead of an IP address.ssh pi@raspberrypi.local– connects to the Pi over SSH from another computer on the same network.sudo nmap -sn 192.168.1.0/24– scans your local network to find all devices and their IPs (install withsudo apt install nmap).scp file.txt pi@raspberrypi.local:/home/pi/– copies a file to the Pi securely.rsync -avz /local/folder/ pi@raspberrypi.local:/remote/folder/– syncs folders over SSH, great for backups.
To keep SSH connections alive (so they don’t drop after inactivity), edit /etc/ssh/sshd_config and add ClientAliveInterval 60, then restart SSH with sudo systemctl restart ssh.
Storage, Partitioning, and Backup
SD cards are the most common failure point on a Pi. Regular backups and careful disk management can save you from losing data.
sudo fdisk -l– lists all disks and partitions (e.g.,/dev/mmcblk0for the SD card).sudo dd if=/dev/mmcblk0 of=backup.img bs=4M status=progress– creates a full image of the SD card. Restore withdd if=backup.img of=/dev/mmcblk0(be very careful with the output device—you can overwrite your main drive).sudo raspi-config→ Advanced Options → Expand Filesystem – grows the root partition to fill the SD card after flashing an image that’s smaller than the card.sudo apt install rpi-clone– clones the running system to a second SD card (or USB drive) for quick swapping.sudo mount /dev/sda1 /mnt/usb– mounts an external USB drive. To auto-mount at boot, add an entry to/etc/fstab.
For scheduled backups, create a cron job: crontab -e and add a line like 0 2 * * * rsync -a /home/pi /mnt/backup/ to sync your home directory every night at 2 AM.
Common Problems and Their Command Line Fixes
Many common Raspberry Pi issues have simple command line solutions.
- Pi won’t boot – Check the SD card with
sudo fsck /dev/mmcblk0p2(unmount first). Corrupted filesystems are a leading cause. - Undervoltage warning (lightning bolt icon) – This means the power supply can’t deliver enough current. Try a different USB cable or power adapter, and check
vcgencmd get_throttledto confirm. - Wi-Fi disconnects – Edit
/etc/wpa_supplicant/wpa_supplicant.confand addcountry=US(or your country code), then reboot. - Time is wrong – Install an RTC or run
sudo timedatectl set-ntp trueto use NTP. Without internet, the Pi has no battery-backed clock. - Command not found – Many tools aren’t pre-installed. Use
sudo apt update && sudo apt install <package>to get them.
Frequently Asked Questions
How do I find my Raspberry Pi’s IP address without a monitor?
If you can’t log in, use your router’s admin page to see connected devices, or run a network scan from another computer with nmap -sn 192.168.1.0/24 (adjust the subnet to match your network). Many routers also let you set a static DHCP reservation so the IP never changes.
Is it safe to overclock my Raspberry Pi?
Overclocking is generally safe because the firmware automatically throttles the CPU at 85°C, and the official tool only allows modest increases. The main risks are instability (crashes) and reduced lifespan due to higher heat. Always monitor temperatures and revert if you see crashes or throttling.
What does the ‘vcgencmd get_throttled’ output mean?
The output is a hexadecimal bitmask. 0x0 means no issues. 0x1 indicates undervoltage occurred, 0x2 means arm frequency capped, 0x4 means throttling, and 0x8 means soft temperature limit active. Values like 0x50000 mean throttling has happened since boot. You can decode it with online tools or the vcgencmd documentation.
How do I run a Python script automatically at boot?
The cleanest way is to create a systemd service as shown above. Alternative methods include adding @reboot python3 /home/pi/script.py to your crontab (crontab -e), but systemd gives you better logging and restart options.
Can I use a USB drive instead of an SD card?
Yes, the Raspberry Pi 4 and later can boot from USB. Use the Raspberry Pi Imager to write the OS to a USB drive, then hold the boot button (on Pi 4) or set the boot order in /boot/config.txt (on Pi 5). USB drives are often more reliable than SD cards for heavy I/O.
Why is my Pi so slow?
Check CPU temperature with vcgencmd measure_temp—if it’s above 80°C, thermal throttling is reducing performance. Also check for undervoltage with vcgencmd get_throttled. Other causes include a nearly full SD card (keep at least 10% free), too many background services, or a slow SD card (class 10 or A2 recommended).
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Handwriting vs Typing for Digital Note Taking2,400 words
- Configure SSL Certificate HAProxy: Step-by-Step
- Ryobi Hybrid Tools: Smart Buy? Here’s Why
- M4 vs M3: Apple Silicon Compared
- Red Flags: Avoid a Social Media Platform?
- Can a Ford Sedan Beat a Mustang? Facts