While Raspberry Pi offers a desktop GUI interface, many prefer using the command-line for faster performance. If you’re one of those people, you must know some useful Raspberry Pi commands to make your life easier. This set of commands will help you manage the Raspberry Pi through the Terminal. Also, if you are setting up Raspberry Pi without a monitor or Ethernet cable, learning these commands will help you a lot. So without any delay, let’s check out the 30 best Raspberry Pi commands you should know in 2021.

Here, we have included both basic and advanced commands for Raspberry Pi. Based on your expertise level, go through the list and put these commands to good use. Just expand the table below and check out the complete list of commands.

  • Update Raspberry OS
  • Access Raspberry Pi Configuration
  • Network Configuration Details
  • Open and Edit a Text File
  • Restart Your Raspberry Pi
  • Power Off Raspberry Pi
  • Find a File
  • Run a Script
  • List Files and Directories
  • View Background Tasks
  • Install a Program
  • Scan the Local Network
  • Find the IP Address of Raspberry Pi
  • Download a File
  • Check Raspberry OS Version
  • Check Current Directory
  • Check Hardware Information
  • Start GUI from Command Line on Raspberry Pi
  • Create Directory
  • Delete Files or Folder
  • Check Files by Extension
  • Elevated Permission
  • Change File Ownership
  • Secure Shell
  • Extract Files
  • Extract TAR Files
  • Search for Text Within Files
  • Change Password of Raspberry Pi
  • Upgrade Raspberry Pi OS Distribution
  • Remove a Package

1. Update Raspberry OS

sudo apt-get update sudo apt-get upgrade

2. Access Raspberry Pi Configuration

sudo raspi-config

ifconfig

Since people use Raspberry Pi for mostly networking things, you must know all the network configuration details. Simply type the above command in the Terminal to find information about the Ethernet, Wi-Fi details such as IP address, MAC address, and more. I think ifconfig is one of the best Raspberry Pi commands, and you should remember it to find all the network information quickly.

sudo nano filename

or

This may seem like a basic Raspberry Pi command, but believe me, this is the command you will be using the most while dealing with system files. Whenever you have to modify the repository or add a new client to /etc/hosts, you can execute this command to open the file with Nano editor. Keep in mind that Nano is a keyboard-based editor, and you can’t use your mouse.

5. Restart Your Raspberry Pi

sudo reboot

As the command suggests, it lets you restart your Raspberry Pi within seconds. Run the command in the Terminal, and your Raspberry Pi will automatically shut down and turn on itself.

shutdown -h now

Similarly, you can run the above command to turn off your Raspberry Pi. In fact, you can schedule the shutdown too. Just replace now with a specific time such as 02:15, and the Raspberry Pi will shut down at 2:15 am. Just remember, Raspberry Pi follows the 24-hour clock.

find / -name filename

I would say find is one of the best commands for Raspberry Pi. It lets you quickly look for a file within the whole system and shows where the file is located. This way, you can save a lot of time instead of hunting down a specific file manually.

chmod a+x filename.sh ./filename.sh

Sometimes you download a script file (.sh) and want to run it on your Raspberry Pi, but all you get from the Terminal is the “Permission denied” output. That’s because the script’s property has not been changed to executable. To do that, use the first command, and it will become executable. Next, run the second command, and the script should work without any issues.

ls

ls is a basic Raspberry Pi command, but it allows you to quickly view files and folders under the current directory. As you move along, you will find yourself using this command pretty often.

htop

sudo apt-get install programname

12. Scan the Local Network

sudo apt-get install nmap nmap -sn 192.168.1.0/24

The nmap command will come in handy if you want to find out the IP addresses of all the locally connected devices. This command is especially helpful if you have set up Pi-hole on your Raspberry Pi. So if you want to scan the local network, use nmap. That said, you will first need to install it (using the first command listed above) as it does not come preinstalled with Raspberry OS.

hostname -I

It’s important that you know the IP address of your Raspberry Pi as it is used almost everywhere, be it for VNC Connect or SSH. So just run the above command, and you will get Raspberry Pi’s IP address instantly.

wget URL

cat /proc/version

If you want to check which version of Raspberry OS you are running, along with the Linux information, execute the above command to get the information right away. It will help you download packages and dependencies based on your current OS version.

16. Check Current Directory

pwd

pwd is a simple Raspberry Pi command to check your current directory. Sometimes, while working through many directories and subfolders, users forget which directory they are in. So type pwd in the Terminal to get the current directory location.

lscpu cat /proc/meminfo cat /proc/partitions

On Raspberry Pi, you can check out hardware information with the above commands. While lscpu lets you find information about CPU cores, meminfo offers you memory information and partitions gives information about SD card size.

startx

If you are on a command-line interface and want to move to the GUI desktop interface, you need to execute the startx command in the Terminal. Do keep in mind, you must have Raspberry Pi Desktop OS installed on your board. If you have installed the Lite OS version, this command will not work. I think startx is among the best Raspberry Pi commands for power users.

mkdir foldername

If you want to create a directory under the current folder, use the mkdir command along with a folder name, and it will be created instantly. You can then use ls to check the said directory.

rm foldername

or

rm filename

rm is again a Linux command that lets you delete a file or folder right from the Terminal. Just enter rm along with the file or folder name.

cat *.txt

If you want to sort files based on the file extension like TXT, PDF, etc., you can use the cat command. This command works like a charm on Raspberry Pi.

sudo su

On Raspberry Pi, if you get the “Permission denied” output, it means you don’t have the privilege to modify or access that file. In such cases, you can type sudo su and hit enter to get into the elevated permission mode. Now, you can execute the command and won’t face any errors.

sudo chown pi:root filename

Generally, files are owned by root on Raspberry Pi, and if you want to access them, you will face an error. In such cases, you need to change the ownership of the file to pi. It requires you to use the above command as you’re dealing with system files and folders in the Terminal.

ssh pi@[IP Address of Raspberry Pi]

If you want to access Raspberry Pi’s terminal from any other local device, you can use the SSH command from Command Prompt, Powershell, Linux Terminal, Mac Terminal, etc. Just add the IP address of your Raspberry Pi in the command above and type yes when asked. Finally, enter the password, which usually is raspberry.

25. Extract Files

unzip filename

The unzip utility is such a useful Raspberry Pi command. No matter the file size, just enter unzip before the filename to extract the files in the current directory.

tar -cvzf filename.tar.gz

Raspberry OS has native ability to extract TAR files as well. Use the command above and enter the actual filename, and it will extracted then and there.

grep keyword *.txt

The grep command is a powerful utility that allows you to search for keywords inside different file types. Replace the keyword with your actual search string, and it will look for that keyword in all TXT files in that directory. You can also replace TXT with PDF and other file formats.

passwd

If you want to change the default password of Raspberry Pi, just enter passwd and hit enter. Now, enter the current password and then enter the new password, and you are done.

sudo apt-get dist-upgrade

If a new update to Raspberry Pi has been released and you want to move to the latest build then run the above command. This process will take time so keep patience.

30. Remove a Package

sudo apt-get remove packagename

If you want to uninstall a program or a package from Raspberry Pi, execute the remove command along with the package name. It will be removed immediately.