Raspberry Pi Command Cheat Sheet

The Raspberry Pi might not be the only single-board computer (SBC) on the market, but it's arguably the most popular maker board. With a variety of different models including the Raspberry Pi 4, Raspberry Pi 400, Raspberry Pi Zero, and the Raspberry Pi Zero W, there are several different models to pick from. Excellent first- and third-party support makes the Pi a great choice for new makers and seasoned do-it-yourselfers (DIYers) alike. While you'll want to select the best Raspberry Pi to fit your needs as well as find the right hardware and software for the job, you'll also need to know the right commands. Here's a Raspberry Pi command cheat sheet for everything from performing software updates to interfacing with GPIO components and more!

sudo

sudo

Running certain commands requires superuser permissions. To execute a command using superuser permissions, add sudo beforehand. For instance, sudo apt-get update updates the list of installed software packages with superuser permissions. 

​sudo raspi-config

​sudo raspi-config

On Raspberry Pi OS, you can start the Raspberry Pi configuration tool using ​sudo raspi-config. This lets you easily customize various settings

sudo apt-get update

sudo apt-get update

Running sudo apt-get update will update the list of installed packages without actually installing anything. 

sudo apt-get upgrade

sudo apt-get upgrade

After updating the list of installed packages using sudo apt-get update, you can download and install updates with sudo apt-get upgrade

sudo apt-get update && upgrade

sudo apt-get update && upgrade

To download updates for installed packages on your Raspberry Pi, you'll first need to run an update of underlying packages with sudo apt-get update, but nothing will be installed until you run sudo apt-get upgrade. Rather than running separate commands, you can string them together with sudo apt-get update && upgrade which updates the package list, downloads, and installs software in one command. 

sudo apt-get install [package name]

sudo apt-get install [package name]

You can install programs via the command line using sudo apt-get install [package name]. For instance, sudo apt-get install kodi will install the Kodi media centre on the Raspberry Pi.

ifconfig

ifconfig

If you need to check on wireless connections, for instance whether or nor wlan0 has an IP address, you can run ifconfig.

iwconfig

iwconfig

Using iwconfig you can check on the network currently being utilized by the wireless adapter. 

ls

ls

A simple but effective command, ls lists the contents of the current directory. You can pair this with various commands to perform other actions. For instance, ls -a will list all files including hidden files like dotfiles that begin with a period. Or ls -l lists the contents of the current directory with added information, while ls [path] will list the contents of a specific directory. 

lsusb

lsusb

For situations where you need to view connected USB peripherals, lsusb will list all USB hardware connected to your Raspberry Pi. 

cd

cd

To change directories using the command line, simply run cd. I.e. cd /home/pi will navigate into the /home/pi directory where you can download programs or access files via the command line. This is particularly useful if you've downloaded software to your downloads folder that you then need to install via the command line, in which case you could run cd /home/user/Downloads.

cp

cp

While a graphical user interface (GUI) is great for moving files and folders, you can also do so using the command line. Running cp [source 1] [source 2] lets you copy one file from one source to another. And cp - r [source 1] [source 2] lets you copy all of the files along with subdirectories from one source to another. 

mkdir

mkdir

Creating a new directory is as easy as running mkdir

rmdir

rmdir

You may also want to remove a directory using rmdir

mv

mv

Moving files around rather than copying them is essential. Running mv [source] [destination] lets you move a file from one source to a different destination. And mv -r migrates files and all directories from the source to a new destination. 

rm

rm

You can remove files using rm, for example rm sample.txt

sudo ​chown pi:root [name]

sudo ​chown pi:root [name]

Permissions on Linux can be tricky. To change the owner of [name] to Pi and set the group as a root user, run sudo ​chown pi:root [name].

sudo reboot

sudo reboot

You can quickly reboot your Raspberry Pi from the command line with sudo reboot

sudo shutdown -h now

sudo shutdown -h now

Perform a safe shutdown of your Raspberry Pi with sudo shutdown -h now.

pwd

pwd

It can be useful to display the name of the directory you're currently working in which can be accopmlished with pwd.

chmod [who][+,-,=][permissions] [name]

chmod [who][+,-,=][permissions] [name]

You can change the permissions of who owns a file with chmod [who][+,-,=][permissions] [name].

chmod u+x [name]

chmod u+x [name]

Sometimes you'll need to execute permissions for the owner of a file which can be accomplished with chmod u+x [name].

chmod 777 [name]

chmod 777 [name]

Running chmod 777 [name] will allow all users to read, execute, and write a file. 

tar -xvzf [name]

tar -xvzf [name]

With tar -xvzf [name] you can extract the contents of a compressed file such as a tar.xz or tar.gz. If you instead run tar -cvzf [name] [path] you can extract the contents of that compressed file to a specific path. 

sudo apt install libwidevinecdm0

sudo apt install libwidevinecdm0

The Raspberry Pi is a nifty little single-board computer. At launch, the Raspberry Pi 4 couldn't stream from the likes of Netflix, Hulu, Disney+, and Spotify because it lacked the proper DRM (digital rights management) in Widevine. However, now the Raspberry Pi has an official widevine package. Simply install it using sudo apt install libwidevinecdm0. Then, you'll be able to stream from premium sites such as Hulu, Netflix, HBO Max, and more!

sudo apt install steamlink

sudo apt install steamlink

Steam is one of the most popular digital PC game delivery services on the market. In addition to offering digital computer games for purchase, Steam offers a whole host of different features including remote play and in-home streaming. Its Steam Link app lets you stream games to compatible devices such as Android or iOS mobile devices, Android TV and tvOS devices, and the Raspberry Pi. Installing Steam Link for the Raspberry Pi is as simple as running sudo apt install steamlink.

Raspberry Pi Command Essentials Cheat Sheet

What commonly used Raspberry Pi commands do you use? Comment below to let us know, and happy making!

Leave your feedback...