30 Raspberry Pi Commands You Need To Know

30 Raspberry Pi Commands You Need To 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.

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.

30 Essential Raspberry Pi Commands

1. Update Raspberry OS

sudo apt-get update 
sudo apt-get upgrade

These two commands allow you to update the Raspberry OS, both the desktop GUI and Terminal-based interface, to the latest build.In addition, they also updates existing packages, dependencies, and repositories.

If you have just set up a Raspberry Pi for the first time, make sure to run these commands one by one to get the latest version of the software.

30 Raspberry Pi Commands You Need To Know

2. Access Raspberry Pi Configuration

sudo raspi-config

Following the update commands, the command sudo raspi-config stands as an incredibly useful tool for Raspberry Pi users. This command grants access to the essential settings and configurations of your device. With it, you can activate the GUI interface, enable the VNC server for remote Raspberry Pi access, modify the screen resolution, activate SSH, and much more.

3. Network Configuration Details

ifconfig

Since networking is one of the most common applications for the Raspberry Pi, it’s crucial to be familiar with all the network configuration details. Enter the command mentioned above in the Terminal to quickly gather essential information such as Ethernet and Wi-Fi details, including IP address, MAC address, and more.

4. Open and Edit a Text File

sudo nano "filename"

or

sudo nano "filepath"

While it might appear straightforward, this command is actually one of the most frequently used when managing system files on the Raspberry Pi. If you need to edit the repository or add a new client to /etc/hosts, this command opens the file in the Nano editor. Remember, Nano operates primarily through keyboard commands; mouse usage is not supported.


You Might Like: Meet The Raspberry Pi 5


5. Restart Your Raspberry Pi

sudo reboot

This command is a quick and efficient way to reboot your Raspberry Pi. Simply execute it in the Terminal, and your Raspberry Pi will automatically shut down and then power itself back on, all within a matter of seconds.

6. Power Off Raspberry Pi

shutdown -h now

This command provides a straightforward method to power off your Raspberry Pi. Additionally, it offers the flexibility to schedule a shutdown. By replacing ‘now’ with a specific time, such as ’02:15′, you can set your Raspberry Pi to shut down at that exact time. It’s important to note that the Raspberry Pi operates on a 24-hour clock format.

7. Find a File

find / -name "filename"

The find command is arguably one of the most efficient tools for Raspberry Pi users. It enables you to swiftly search for a file throughout the entire system and reveals its location. This functionality can save a considerable amount of time that would otherwise be spent manually searching for a specific file.


You Might Like: Using Color Sensors


8. Run a Script

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

Occasionally, when you download a script file (with a .sh extension) and attempt to run it on your Raspberry Pi, you might encounter a “Permission denied” message in the Terminal. This happens because the script file hasn’t been granted executable permissions. To resolve this, use the first command to change the script’s properties to executable. After doing so, execute the second command to run the script, and it should function smoothly without any permission issues.

9. List Files and Directories

ls

The ls command, while basic, is an essential tool for Raspberry Pi users. It enables you to swiftly view the files and folders within the current directory. As you become more familiar with the Raspberry Pi, you’ll likely find yourself using this command quite frequently.

10. View Background Tasks

htop

In my opinion, htop stands out as one of the most useful commands for Raspberry Pi users. It’s akin to Windows’ Task Manager but operates within a Terminal-based interface. This command allows you to monitor various system metrics such as RAM usage, CPU load, the number of background tasks, uptime duration, and much more. A particularly valuable feature of htop is its ability to display the CPU temperature, which is crucial for managing Raspberry Pi’s performance. Additionally, it provides the Process ID (PID) for each task, enabling you to terminate any process using the kill command.

raspberry pi commands

11. Install a Program

sudo apt-get install "programname"

To install an app or utility on your Raspberry Pi, simply use the provided command. Substitute programname with the actual package name of the program you wish to install and press enter. The app will be promptly installed on your system.

12. Scan the Local Network

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

The nmap command is particularly useful for identifying the IP addresses of all devices connected to your local network. This command is especially beneficial if you’ve set up Pi-hole on your Raspberry Pi. To scan your local network, nmap is the tool to use. However, keep in mind that it doesn’t come pre-installed with Raspberry Pi OS, so you’ll need to install it first, using the installation command mentioned earlier.

13. Find the IP Address of Raspberry Pi

hostname -I

Knowing the IP address of your Raspberry Pi is crucial since it’s used in various scenarios, such as setting up VNC Connect or SSH connections. Simply execute the aforementioned command, and you’ll instantly receive the IP address of your Raspberry Pi.


You Might Like: Creating A Raspberry Pi Airplay Receiver


14. Download a File

wget "URL"

wget ranks as one of my favorite commands for the Raspberry Pi. It’s a built-in downloader for Linux-based operating systems. To use it, just type wget followed by the URL of the file you want to download and press enter. The file will be downloaded and saved in the current directory you’re in. It’s a remarkably convenient and efficient tool, don’t you think?

30 Raspberry Pi Commands You Need To Know

15. Check Raspberry OS Version

cat /proc/version

To find out which version of Raspberry Pi OS you are using, as well as to obtain detailed Linux information, simply run the command mentioned above. This will promptly provide you with the necessary details. Knowing your current OS version is particularly useful for downloading the appropriate packages and dependencies tailored to your system.

16. Check Current Directory

pwd

pwd is a straightforward command for Raspberry Pi users to determine their current directory. When navigating through numerous directories and subfolders, it’s easy to lose track of your exact location. By typing pwd in the Terminal, you can quickly find out the path of the directory you’re currently in.

17. Check Hardware Information

lscpu 
cat /proc/meminfo 
cat /proc/partitions

On the Raspberry Pi, you can access detailed hardware information using the commands mentioned above. The lscpu command is useful for gathering information about the CPU cores, such as their number, architecture, and speed. The meminfo command provides insights into the memory, including total RAM and available memory. Lastly, the partitions command gives information about the SD card size, detailing the storage capacity and partition layout of your Raspberry Pi’s primary storage medium.

18. Start GUI from Command Line on Raspberry Pi

startx

If you’re working in a command-line interface on your Raspberry Pi and wish to switch to the GUI desktop interface, the startx command is what you need. It’s important to remember, though, that this command requires the Raspberry Pi Desktop OS to be installed on your board. If you have the Lite OS version installed, the startx command won’t be effective. In my opinion, startx stands out as one of the best Raspberry Pi commands, particularly for power users who frequently switch between command-line and graphical interfaces.


You Might Like: How To Use Steam On Your Raspberry Pi


19. Create Directory

mkdir "foldername"

To create a new directory within the current folder on your Raspberry Pi, utilize the mkdir command followed by your desired folder name. This command will instantly create the specified directory. Afterwards, you can confirm its creation by using the ls command to view the contents of the current folder, including the newly created directory.

20. Delete Files or Folder

rm "foldername"

or

rm "filename"

The rm command is a standard Linux command used to delete files or folders directly from the Terminal. To use it, simply type rm followed by the name of the file or folder you wish to delete. This command provides a quick and efficient way to manage your file system on the Raspberry Pi.

21. Check Files by Extension

cat *.txt

To sort files based on their file extensions, such as TXT, PDF, etc., on a Raspberry Pi, the cat command can be used, although it’s primarily designed for displaying the contents of files. For sorting files, you might want to use a combination of commands like ls and grep. For example, ls | grep '.txt' would list all files with the ‘.txt’ extension. The cat command is great for concatenating and displaying file contents, but for sorting files by extension, ls and grep are more effective.

22. Elevated Permission

sudo su

On the Raspberry Pi, encountering a “Permission denied” message indicates a lack of necessary privileges to modify or access a particular file. To overcome this, you can enter the elevated permission mode by typing sudo su and pressing enter. This grants you superuser access, allowing you to execute commands without facing permission-related errors. Remember to use this elevated access responsibly, as it gives you the ability to make significant changes to the system.

23. Change File Ownership

sudo chown pi:root "filename"

A significant number of files are usually owned by the ‘root’ user. If you try to access these files without suitable permissions, an error is likely to occur. To remedy this situation, you have the option to alter the file ownership to the ‘pi’ user. This action demands the use of a specific command, which is particularly crucial when managing system files and folders via the Terminal. Altering the file ownership to ‘pi’ effectively provides you with the required permissions for these files.


You Might Like: Raspberry Pi VS Jetson Nano


24. Secure Shell

ssh pi@[IP Address of Raspberry Pi]

To connect to your Raspberry Pi’s terminal from another device on your local network, you can utilize the SSH command. This command works across various platforms, including Command Prompt, PowerShell, Linux Terminal, and Mac Terminal. Start by including your Raspberry Pi’s IP address in the command. When prompted, type ‘yes’ to proceed. Then, you’ll need to enter the password, which typically defaults to ‘raspberry’. This process allows you to remotely access your Raspberry Pi’s terminal with ease.

25. Extract Files

unzip "filename"

The unzip command is incredibly handy on the Raspberry Pi, providing a simple solution for extracting files. Regardless of the file’s size, simply type unzip followed by the filename, and the contents will be extracted right into your current directory. This utility makes managing compressed files straightforward and efficient.

26. Extract TAR Files

tar -cvzf "filename".tar.gz

Raspberry Pi OS comes equipped with the native capability to extract TAR files. By using the command provided and specifying the actual filename, you can easily extract the contents of the TAR file on the spot. This built-in feature simplifies the process of handling TAR archives in the Raspberry Pi environment.

27. Search for Text Within Files

grep "keyword" *.txt

The grep command is an exceptionally powerful tool on the Raspberry Pi, enabling you to search for specific keywords within various file types. Simply replace ‘keyword’ in the command with the actual term you’re searching for, and it will scan through all TXT files in the current directory for that keyword. This command is versatile enough to be used with other file formats too; just substitute TXT with PDF or any other file extension to tailor your search.

28. Change Password of Raspberry Pi

passwd

To update the default password on your Raspberry Pi, simply type in passwd and press enter. You’ll first need to input the current password, followed by your new chosen password. Once you’ve completed these steps, your Raspberry Pi’s password will be successfully changed.

29. Upgrade Raspberry Pi OS Distribution

sudo apt-get dist-upgrade

If there’s a new update available for Raspberry Pi and you wish to upgrade to the latest build, execute the aforementioned command. Be prepared for this process to take some time, so patience is key while your Raspberry Pi updates to the newest version.

30. Remove a Package

sudo apt-get remove "packagename"

To uninstall a program or package from your Raspberry Pi, use the remove command followed by the name of the package. This action will promptly remove the specified program or package from your system.

Final Thoughts

Mastering these 30 essential commands can significantly enhance your experience with the Raspberry Pi. From basic file management to system updates, and from network configuration to security enhancements, each command offers a unique function that contributes to the efficient and effective use of this versatile device.

Whether you’re a beginner learning the ropes or a seasoned user looking to streamline your workflow, these commands provide the foundational knowledge necessary to navigate and optimize your Raspberry Pi’s potential. Embrace these tools, and you’ll find yourself unlocking new levels of productivity and innovation with your Raspberry Pi.

Erik D

Leave a Comment

Your email address will not be published. Required fields are marked *