If you click our links and make a purchase, we may earn an affiliate commission.
Learn more
Starting out on a Raspberry Pi is not always easy because you don’t necessarily have the habit of using the command line. However, terminal commands are essential and are often more efficient than going through the GUI. What vital commands should you know?
There are quite a few, and here we will see the 57 most used commands sorted by category:
This list is based on my general experience with Raspberry Pi and Linux. We all use our systems differently, and you might use commands that aren’t listed here. The goal of this article, however, is not to make an exhaustive list but to introduce you to the essential commands. Let’s get started.
These are the basic commands are that every Linux beginner should learn. You might already know these commands, so this might be a refresher.
The Linux files organization is a tree, starting at the root: / Each subfolder created under it is accessible starting with /. For example: /var/log ⇒ log is a subfolder of /var, var is a subfolder in /.
Don’t forget to use sudo if you are not allowed to access the file or directory (sudo gives you administrator privileges for the command that follows).
Lost in the terminal? Grab My Pi Cheat-Sheet! Download the free PDF, keep it open, and stop wasting time on Google. Download now
Stuck on Another Raspberry Pi Tutorial? Get real answers from 500+ experienced makers, plus exclusive monthly video lessons and ad-free browsing. See What's InsideGet Unstuck Today ($9 only)
cd <path>: Changes directory, go to the specified folder in the files tree. cd /home/pat
ls: Lists the files and directory in the current or specified folder. ls /home/pat ls -latr /home/pat
mkdir <folder>: Creates a new subfolder in the current or specified folder. mkdir myfolder mkdir /home/pat/myfolder
cp <file> <destination>: Copies a file or a directory to another location (to copy a complete directory you need to add the -r parameter for “recursive”). cp test.txt /home/pat/Documents/ cp /home/pat/test.txt /home/pat/Documents/ cp -r /home/pat/test/ /home/pat/Documents/
mv <source> <destination>: Moves a file or a directory to another location. mv /home/pat/test.txt /home/Documents/ mv /home/pat/test/ /home/Documents/
cat <file>: Displays all the content of the specified file. cat /home/pat/README.txt
more <file>: Displays the content of the specified file, page per page (enter or space to continue, q to quit). more /var/log/syslog
tail <file>: Tail allows you to display the end of a file, it’s useful to check new entries in a log file. tail /var/log/syslog You can specify the number of lines to display with -n. tail -n20 /var/log/syslog And finally, my favorite is the option -f to displays new lines in real-time. tail -f /var/log/syslog
head <file>: It’s the same as tail but to display the beginning of a file. head /home/pat/file.txt head -n20 /home/pat/file.txt
grep <string>: Grep is a powerful tool to search string in a text. You can use it to search something in a file or to filter the output of another command or script. Basic usage: grep dhcp /var/log/syslog
As I say, you can use it on a file or a script output: cat /var/log/syslog | grep dhcp /home/pat/myscript.sh | grep error ls -latr | grep php
And finally, there are a lot of options to use with grep, like regular expressions or options to display lines before (-B), after (-A) or around (-C) the search string. You can also use -v to display everything except the input string. grep 'dhcp|dns' /var/log/syslog grep -A2 -B4 'Fatal error' /var/log/apache/error.log grep -v 'Notice' /var/log/apache/error.log
If you like this tool, I recommend you read the man page to know exactly what you can do with it. man grep And you can also read my dedicated article about grep here.
nano <file>: Nano is text editor. It would need an entire article to go into detail (I have done it since, click here to read more about it ^^). It allows you to edit a file, and save your changes with (CTRL + O, Enter, CTRL + X). nano /home/pat/myscript.sh
You’ll find all actions available at the bottom of the screen.
rm <file>: Deletes a file. For a folder, add option -rf (recursive and force) rm monscript.sh rm -rf /home/pat/scripts/
Be really careful if you are using sudo with this command. Using it on system folders will delete everything without any warning message, and can break your system in a few seconds.
tar -c: You can use tar to store files into an archive. It’s often used with gzip to compress files. tar -cvfz archive.tar.gz /home/pat/Documents/mydirectory
-c: create an archive -v: verbose -f: filename of the archive follow -z: compress files with gzip
tar -x: It’s the same command but to extract files. tar -xvfz archive.tar.gz -x: extract an archive
find: As the name suggests, find is useful to locate files on your Raspberry Pi. find /home/pat -iname *.tar.gz
There are many options to help you find the good file (size, last modification date, …). And if you want to learn options to quickly find a file on Raspberry Pi, you can also read this other article on the topic.
pwd: Pwd lets you see in which directory you are. pwd
tree: Another great tool to analyze your current location in the file tree. It will show you the entire lower tree (see the example below). tree
There is a cheat sheet available here that you can download for free, with all the commands listed in this article (in fact there are a few bonuses in the PDF). Make sure to download it, so you always have it handy when you use your Raspberry Pi.
Shortly after your first Raspberry Pi OS installation, you’ll need some of these commands to help you with configuring your network (especially if you’re on the Lite version or with SSH).
Network Configuration
By default, the Raspberry Pi 3B+ comes with two interfaces (Ethernet and Wi-Fi). The Ethernet is assigned eth0 and the Wi-Fi is wlan0. You have to use these names in some commands below.
ip address: Displays your current network configuration, mainly your IP address if connected. ip a That’s the easiest way to find the Raspberry Pi address, but there are other solutions when you don’t have access to it (as I explain in this article).
ping <ip>: Sends a ping packet to another IP on the network to check if the host is alive. ping 192.168.1.1
ip link set <interface> up: Enables the specified interface. sudo ip link set eth0 up
ip link set<interface> down: Disables the specified interface. Can be useful to disable Wi-Fi if you are already connected by cable for example. sudo ip link set wlan0 down
By the way, it’s a great idea to disable the Wi-Fi interface if you don’t use it. You can find more permanent solutions in this article, but this command is a quick way to do this.
File Transfer and Remote Connection
wget <url>: This command allows you to download a file from the Internet. wget https://wordpress.org/latest.zip
scp <file> <user>@<ip>:<path>: scp can transfer a file to a remote computer over SSH. scp test.txt [email protected]:/root/
rsync <file> <user>@<ip>:<path>: rsync does almost the same thing but with a delta comparison algorithm and some optimizations to transfer files faster. rsync test.txt [email protected]:/root/ rsync -auzr /home/pat/Documents/* /home/pat/backups/Documents/
I generally use this command to back up my Raspberry Pi (as explained here). I send all these important files to my local NAS (I’m using this device). It takes a few seconds and I know I’m safe after that.
System Updates
Just after the network configuration, you’ll have to update your system to get the latest version of each default package installed.
Lost in the terminal? Grab My Pi Cheat-Sheet! Download the free PDF, keep it open, and stop wasting time on Google. Download now
Stuck on Another Raspberry Pi Tutorial? Get real answers from 500+ experienced makers, plus exclusive monthly video lessons and ad-free browsing. See What's InsideGet Unstuck Today ($9 only)
On Raspberry Pi OS, and generally on all Linux distributions, you’ll have a package for each app or command you install. A list of all available packages is called a repository. Once installed, you need to update this repository and all of your packages regularly to keep your system safe.
These commands explain how to do this. We’ll need sudo for all of these commands:
apt update: Downloads the last repository version for each one you have in your configuration (/etc/apt/sources.list). sudo apt update
apt upgrade: Updates all installed packages if needed. sudo apt upgrade
rpi-update: Only use this if you know what you’re doing. This command will update everything on your Raspberry Pi (firmware, packages, etc.) and can potentially break something. rpi-update
apt install <package>: Installs the specified package(s). sudo apt install phpmyadmin sudo apt install vim htop
apt remove <package>: Removes a previously selected package. sudo apt remove vim
apt search <search>: Searches for a package name in the packages list (repository). sudo apt search myadmin sudo apt search php
dpkg -l: Lists all installed packages on your system. You can use grep to find a specific package. dpkg -l dpkg -l | grep myadmin
Note: If you want to see all these commands in action, I have a video lesson available for the community members. You can join here and watch it directly if you are interested (with 30+ other lessons for Raspberry Pi and many other benefits).
Lost in the terminal? Grab My Pi Cheat-Sheet! Download the free PDF, keep it open, and stop wasting time on Google. Download now
Here are the commands you’ll often use to manage your Raspberry Pi system:
reboot: As the name says, this command will restart the Raspberry Pi immediately. sudo reboot
shutdown -h now: This is to stop the Raspberry Pi immediately. sudo shutdown -h now
You can replace “now” by a specific time (shutdown -h 12:05). Don’t use the power switch to stop your Raspberry, you should do it properly by using this command or one of the other methods explained here and there.
service <servicename> <action>: This command allows you to start or stop services. service apache2 start service apache2 stop
Sometimes there are other options, depending on the service, for example: service apache2 reload service apache2 restart
Don’t type any action to see all those available: service apache2 For information, you can also use systemctl to do the same thing, on Raspberry Pi OS you have the choice, but on some systems it’s only systemctl.
update-rc.d <service> <action>: On Debian, this command allows you to manage the service start or stop on the system boot. To start a service on boot: sudo update-rc.d ssh enable To disable start of the service: sudo update-rc.d -f ssh remove The -f option is here to force the symbolic link deletion. This command is only for service. To start other scripts or commands on boot, you have to edit the /etc/rc.local file. sudo nano /etc/rc.local
ps: This command displays all running process on your Raspberry Pi. The basic command is this one to display everything: ps aux You can also display process started by a specific user: ps -u pi This will give you a list like this: The process ID (PID) can be useful for other commands, to stop it for example (next command).
kill <pid>: The kill command allows you to terminate a process. You’ll need the process ID to do this (see the previous command). kill 12345
Sometime you may need to use the -9 option to force all related commands to stop. For example, if you run 20 commands in a script and kill it, it’ll continue to the next line, not exit the program, except if you use the -9 option.
kill -9 12345
You can also use killall to stop all occurrences of a program.
killall php
This command will stop all PHP scripts.
Be aware that this command will immediately stop the process asked, no matter what was going on. It isn’t a clean stop.
You don’t know what the script is doing so it can damage data or corrupt files. This should be used as a last step, and if possible on the non-critical process.
htop: This tool is an alternative to top. It’s more user-friendly than top, with colors and dynamic load bars. htop
df: Displays the partition list, with the disk space used and available for each one. df df -h
-h option is for the human-readable format.
vcgencmd measure_temp: You may not remember it, but this command displays the current CPU temperature. vcgencmd measure_temp
Raspberry Pi OS Commands
Most of the commands from this post are basically Linux commands. But Raspberry Pi OS has some exclusive ones that I will introduce.
These are not all essentials, but you may not know them even if you are good with Linux:
raspi-config: This tool allows you to manage all the configuration from a terminal or an SSH connection. sudo raspi-config Check out my full guide on raspi-config here.
rpicam-still: If you have a camera plugged in the camera module, this command takes a shot and saves it as an image file. rpicam-still -o image.jpg
Note: On older Raspberry Pi OS versions, the commands were libcamera-still or raspistill. For the next command, the old commands were libcamera-vid and raspivid.
rpicam-vid: It’s the same command but it captures video from the camera. rpicam-vid -o video.h264 -t 10000
-t parameter is the time of the capture in milliseconds.
Note: The commands raspividyuv / raspiyuv have also been replaced by rpicam-vid. So to get a raw YUV video stream, you’d need a command like this: rpicam-vid -t 10000 --codec yuv420 -o test.data
raspi-gpio: This command allows you to manage the Raspberry Pi’s GPIO pins, which are often used with accessories. You can either set or get a value. raspi-gpio get raspi-gpio get 20 raspi-gpio set 20 a5 raspi-gpio set 20 op pn dh
rpi-update: Only use this if you know what you are doing. This will update everything on your Raspberry Pi (firmware, packages, …) and can potentially break something. sudo rpi-update
Misc Commands
Here are some other useful commands that I haven’t managed to place in the other categories :):
history: Linux store any command you type in an archive file. History is the command to use to display this list. history You can also clear all the history. history -c Or clear one specific entry. history -d 12
crontab: Cron is a tool to schedule tasks on a Raspberry Pi. Crontab is the file where you enter lines for each task to run. crontab -l crontab -e
-l option to display lines. -e option to edit lines.
You can use sudo before to schedule tasks to run with root privileges. I have an entire tutorial on this topic if you need more information.
screen: This tool allows you to let something run in the background even if you close your session. screen -s <name> screen -r <name>
-s option to start a new screen with the following name. -r option to resume a running screen with this name. You can forget the name if you want, an ID will be generated, use screen -r to find it and screen -r <ID> to resume it. With only one screen running, screen -r will resume it directly.
🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!
If this project doesn’t work as expected on your setup, don’t worry. You can get help directly from me and other Pi users inside the RaspberryTips Community. Try it for $1 and fix it together.
In this last part, I’ll introduce some power user commands to master your Raspberry Pi. If you start on Linux, you may not need to know this one, but if you want to save time or go further on Raspberry Pi, you should know this commands
awk: awk is nearly a programming language, it allows you to search string and transform them to display it differently. So it’ll be difficult to summarize all the possibilities in a few lines, but I’ll try to give you some examples to understand it. The basic syntax of awk is this one: awk -F":" '{print $1}' /etc/passwd /etc/passwd is the file to parse. The field separator is “:” so we use it in the -F option. Then in the program string, we ask to display only the first column. So this command will display only a list of usernames. This is the simple way to use it if you want to know more, I recommend reading a dedicated tutorial like this one.
sed: sed allows you to do similar things to awk. This command will transform text to what you want. As for awk, it’s a complex command to master, and I’ll only introduce it here. The basic syntax looks like this: sed <option> <script> <file> So it’s very close to awk on this. Let’s see an example: sed '/^#/d' /etc/apache2/apache2.conf
In each configuration file, you’ll find a lot of comments to explain what each line is. This command will display the apache configuration file without comments. We use a regular expression to delete lines starting with #. You have to redirect the output to another file to save it.
sed '/^#/d' /etc/apache2/apache2.conf > /etc/apache2/apache2-nocomment.conf
cut: cut is the last way to transform text that I’ll introduce. It’s less powerful but it’s simpler to use, so if cut can do it, you’ll probably prefer to use it rather than awk or sed. As the name suggests, cut allows you to extract part of a text or file. The basic syntax is: cut <options> <file> echo <string> | cut <options> The first one is for a file, and the second one to cut a string directly.
A basic example now: echo "abcdefghi" | cut -c 2-4 This will display only “bcd”. -c option is for the character, so basically, it’ll extract character 2 to 4.
Here are other options with a file: cut -d : -f 1 /etc/passwd
This will do the same thing as the first example of the awk command. /etc/password is a file with “:” use as a delimiter. -d option is to give the delimiter character (“:”). -f option is to indicate the column to extract (f stands for the field). So, this will display only the first column and you’ll get a list of usernames.
wc: wc stands for Word Count, it allows you to count everything in a file or stream. There are three main options: -l for lines, -w for words and -m for characters. There is also the -c option to get the file size. Wc without option will give you all of this. wc .bash_history 668 1977 17979 .bash_history The first column is line count, second is word count and last is the file size in bytes.
Here are some examples of options: wc -l .bash_history ls -latr | wc -l wc -w myfile.txt
lsof: lsof stands for “List open files”. This command displays all files open on your Raspberry Pi. This can be useful to know why you can’t edit a file, or which file lock the unmount process. lsof
watch: If you are waiting for something, in a file or directory, the watch command can help you to monitor what happens. This will execute the same command every two seconds. watch date watch ls -latr watch cat output.txt You can also change the refresh rate with the -n option. watch -n10 date This will display the current date every ten seconds.
netstat: Netstat is a powerful tool to monitor what your Raspberry Pi is doing with the network. For example, you can see every port open and every traffic flow. But netstat is a complex tool that i can’t explain in detail in a few lines. I will only introduce some basic usages to display all listening connections you can use: netstat -l -p option will add the process id (PID). netstat -lp -c option allows you to refresh data continuously. netstat -lpc You can find all options in the man page of netstat.
dmesg: This command is useful to understand your Raspberry Pi boot problems. It will show you every event that happened in the start sequence. Here you could see errors with drivers or services and understand why something doesn’t work the way you want. dmesg You will get a column with the time elapsed since the beginning of the boot and a text explaining what happened. There are also normal messages when everything is fine. If your Raspberry Pi doesn’t boot, you can also check my other tips here.
Lost in the terminal? Grab My Pi Cheat-Sheet! Download the free PDF, keep it open, and stop wasting time on Google. Download now
Phew, that’s all for today! If you need a quick demonstration of these commands, you can check out this video:
Whenever you’re ready, here are other ways I can help you:
Test Your Raspberry Pi Level (Free): Not sure why everything takes so long on your Raspberry Pi? Take this free 3-minute assessment and see what’s causing the problems.
The RaspberryTips Community: Need help or want to discuss your Raspberry Pi projects with others who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct help (try it for just $1).
Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.
You can also find all my recommendations for tools and hardware on this page.
I'm the lead author and owner of RaspberryTips.com.
My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials.
In real life, I'm a Linux system administrator with web developer experience.
If you click our links and make a purchase, we may earn an affiliate commission. Learn more Being able to control your Raspberry Pi from another computer is an important part of the Pi learning curve. There are many options for remote access, so why is SSH the protocol beginners should start with? If you’re…
If you click our links and make a purchase, we may earn an affiliate commission. Learn more Handling 3D objects is a requirement for numerous applications. Blender is a popular open-source software providing an entire 3D creation suit. However, it is not natively supported on the Raspberry Pi due to its hardware limitations. Fortunately, I…
If you click our links and make a purchase, we may earn an affiliate commission. Learn more Mining crypto on our Raspberry Pi is a dream for many of us, and Monero is a good crypto for CPU mining. So, is it possible to mine Monero on your Raspberry Pi and get decent results? Let’s…
If you click our links and make a purchase, we may earn an affiliate commission. Learn more PostgreSQL, often called Postgres, is an open-source object-relational database management system (ORDBMS). It is known for its robustness, reliability, and scalability. In this article, I shall guide you through the installation and initial configuration of the PostgreSQL server…
If you click our links and make a purchase, we may earn an affiliate commission. Learn more Sonic Pi is a fun project for your Raspberry Pi that lets you create music with lines of code. However, the initial setup and understanding of how to write your first lines can be a bit intimidating. That’s…
If you click our links and make a purchase, we may earn an affiliate commission. Learn more Having extra copies of your Raspberry Pi SD card can be useful in many situations. Maybe you want to make a backup or migrate your whole system. This procedure may sound quite complex, but it’s not that difficult….
11 Comments
Might be nice to title this so that it’s specific to Linux / Raspbian (I understand some of these commands are not exclusive to Raspbian though) — this is a really nice article, but really useless on my Win 10 IoT install. 🙂
why are you on a site called raspberrytips.com looking for windows 10 IOT articles anyway Alex?
You’re using Arch Linux. It doesn’t use apt-get, it uses pacman. Check arch Linux wiki for help. (Search there for “sudo” to get help with the sudoers file as well)
What about adding to “Misc” part ability to execute command from history list by typing “!123” for example which will execute history line 123 without the need to re-type or copy/paste ? That is neat feature.
Is there a command or path that will allow to change the monitor timeout? I have searched the web from end to end and everything i have found does not work
Thank you
Do these also work on NanoPi M4?
I would like to know, how l can define the location where the data has to be stored
It is a RPi B+, os raspbian-stretch, mysql / mariaDB, sdb2 is a usb ssd 240G mounted (/dev/media/pi/)
After several reading literature and tests, I’m not able to find the way to declare the storage location
Hello Max,
To my knowledge you have two options
1/ datadir option in mariadb configuration:
– stop mysql
– move the /var/lib/mysql files to the new location
– edit the configuration file: sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
– find the datadir line and replace “datadir = /var/lib/mysql” with the new path
– start mysql
2/ symbolic link
– stop mysql
– mv the /var/lib/mysql folder to the new location
– delete the /var/lib/mysql folder
– create a symbolic link to the new location (with ln -s)
– start mysql
If the first is not working, the second could be an option
Did you already tried both?
Quite a nice guide! Some commands I never encountered before that seem very useful.
Thanks, Peter 🙂
Comments are closed.
×
Tired of figuring everything on your own?
Join the RaspberryTips Community and learn faster with help from other Pi users, exclusive tutorials, ad-free content, and more.
You can get 7 days of full access for just $1 by using the link below.
Might be nice to title this so that it’s specific to Linux / Raspbian (I understand some of these commands are not exclusive to Raspbian though) — this is a really nice article, but really useless on my Win 10 IoT install. 🙂
why are you on a site called raspberrytips.com looking for windows 10 IOT articles anyway Alex?
great but i need help..
https://i.imgur.com/NzQr2RT.png
how to fix
You’re using Arch Linux. It doesn’t use apt-get, it uses pacman. Check arch Linux wiki for help. (Search there for “sudo” to get help with the sudoers file as well)
What about adding to “Misc” part ability to execute command from history list by typing “!123” for example which will execute history line 123 without the need to re-type or copy/paste ? That is neat feature.
Is there a command or path that will allow to change the monitor timeout? I have searched the web from end to end and everything i have found does not work
Thank you
Do these also work on NanoPi M4?
I would like to know, how l can define the location where the data has to be stored
It is a RPi B+, os raspbian-stretch, mysql / mariaDB, sdb2 is a usb ssd 240G mounted (/dev/media/pi/)
After several reading literature and tests, I’m not able to find the way to declare the storage location
Hello Max,
To my knowledge you have two options
1/ datadir option in mariadb configuration:
– stop mysql
– move the /var/lib/mysql files to the new location
– edit the configuration file: sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
– find the datadir line and replace “datadir = /var/lib/mysql” with the new path
– start mysql
2/ symbolic link
– stop mysql
– mv the /var/lib/mysql folder to the new location
– delete the /var/lib/mysql folder
– create a symbolic link to the new location (with ln -s)
– start mysql
If the first is not working, the second could be an option
Did you already tried both?
Quite a nice guide! Some commands I never encountered before that seem very useful.
Thanks, Peter 🙂