30 Best Raspberry Pi Commands You Should Know

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.

Best Raspberry Pi Commands

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.

1. Update Raspberry OS

sudo apt-get update 
sudo apt-get upgrade

Best Raspberry Pi Commands (2021)

If you are new to Raspberry Pi, you must know these two commands. They allow you to update the Raspberry OS, both the desktop GUI and Terminal-based interface, to the latest build.

Not just that, it also updates existing packages, dependencies, and repositories. So if you have set up a Raspberry Pi for the first time, make sure to run these commands one by one to run the latest version of the software.

2. Access Raspberry Pi Configuration

sudo raspi-config

sudo raspi-config

After the update commands, this is the most useful Raspberry Pi command. sudo raspi-config lets you access all the key settings and preferences of this single board computer. You can enable the GUI interface, turn on the VNC server to remotely access Raspberry Pi, change the resolution, enable SSH, and lots more. I would say, if you want to deal with system settings, run this command in the Terminal and customize most of the preferences to your liking.

3. Network Configuration Details

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.

4. Open and Edit a Text File

sudo nano filename

or

sudo nano filepath

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.

6. Power Off Raspberry Pi

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.

7. Find a File

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.

8. Run a Script

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.

9. List Files and Directories

ls

Best Raspberry Pi Commands (2021)

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.

10. View Background Tasks

htop

htop

In my view, htop is one of the best Raspberry Pi commands. It is similar to the Task Manager on Windows but in a Terminal-based interface. You can view the RAM usage, CPU usage, how many tasks are running in the background, uptime duration, and a lot more. What I love about this command is that it also lets me view the CPU temperature, which is essential for managing RPi. Other than that, you can find the PID (Process ID) and close the task with the kill command.

11. Install a Program

sudo apt-get install programname

Best Raspberry Pi Commands

If you want to install an app or utility on your Raspberry Pi, use the above command. Replace programname with the package name of the program and hit enter. The app will be installed on the system right away.

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.

13. Find the IP Address of Raspberry Pi

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.

14. Download a File

wget URL

Best Raspberry Pi Commands

wget is one of my favorite Raspberry Pi commands. It’s a native downloader for Linux-based operating systems. Just type wget and add the URL from where you want to fetch the files and hit enter. The file will be downloaded and saved in the current directory. How cool is that, right?

15. Check Raspberry OS Version

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.

17. Check Hardware Information

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.

18. Start GUI from Command Line on Raspberry Pi

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.

19. Create Directory

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.

20. Delete Files or Folder

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.

21. Check Files by Extension

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.

22. Elevated Permission

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.

23. Change File Ownership

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.

24. Secure Shell

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.

26. Extract TAR Files

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.

27. Search for Text Within Files

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.

28. Change Password of Raspberry Pi

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.

29. Upgrade Raspberry Pi OS Distribution

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.

Find All the Useful Raspberry Pi Commands

So these are the best Raspberry Pi commands you can use to get things done on your tinker board. I use most of them, and they do suffice my needs. Since Raspberry Pi is essentially running Linux under the hood, you can find the best Linux commands from our curated list. They will work on Raspberry Pi too. Anyway, that is all from us. In case you want to set up a Raspberry Pi web server, head over to our linked tutorial. And if you have any questions, let us know in the comment section below.

Comments 1
Leave a Reply

Loading comments...