19 Simple Raspberry Pi Terminal Commands for Beginners

Introduction

The Raspberry Pi is an awesome single-board computer that you can use to start learning the Linux operating system. It’s got just enough processor power and ram to make itself incredibly useful. In some cases, it can even replace your desktop PC.

This guide is designed to provide beginners with some simple Raspberry Pi terminal commands that will help familiarize them with basic configuration of the Raspberry Pi and how to navigate through the file system via a terminal interface.

Configuring and Managing your Raspberry Pi

Configuring your Raspberry Pi is simple thanks to the Raspberry Pi Configuration tool that is included with the Raspbian operating system. Updating and maintaining your Raspberry Pi can be done with the standard Linux commands. The Raspberry Pi terminal commands are outlined below.

Raspberry Pi Software Configuration Tool

The Raspberry Pi Software Configuration Tool allows you to easily configure some common settings within your Pi. To run the Raspberry Pi Software Configuration Tool, type the following command and hit enter.

sudo raspi-config

You will then be presented with a screen similar to the one show in the below screenshot.

Raspberry Pi Terminal Commands

Once the tool is open, you can change the password to your user account, modify your Network Options (this is where you change your WiFi settings), and configure processor overclocking in the Overclock menu.. Under Interfacing Options, you can enable and disable various ways for you to connect and interface with your Raspberry Pi. You can enable SSH access, and VNC access here.

Updating your Raspberry Pi

After you first get your Raspberry Pi setup, you should some quick commands to the software updated to the latest version. Software updates are important, because not only can they contain new features, but they can also contain security patches to ensure that your system is running as secure as possible.

The first step in the update process is to run the following command.

sudo apt-get update

When you run the apt-get update command in your terminal, your machine will download updated information regarding the various software packages that are installed on your system. The output for that command will be similar to the text snippet below.

Hit:1 http://deb.debian.org/debian unstable InRelease
Hit:2 http://raspbian.raspberrypi.org/raspbian buster InRelease     
Hit:3 http://archive.raspberrypi.org/debian buster InRelease         
Hit:4 https://download.docker.com/linux/raspbian buster InRelease   
Reading package lists... Done                    

Now that you have the latest package information on your system, you can run the below command to upgrade your current install software packages to the new versions.

sudo apt-get upgrade

One you type in the command and hit enter on your keyboard, you will be presented with information similar to the information below. This information outlines what software packages will be upgraded and ask you if you want to proceed. If you want to proceed with the upgrade, type the y key and hit enter.

26 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Need to get 93.7 MB of archives.
After this operation, 4,435 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

After typing y on your keyboard, the upgrade process will continue.

If you do not have any upgrades available, you will be presented with the following output. Note that at the bottom it states 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. This indicates that the software packages installed on your Raspberry Pi are up to date.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

After running the above commands, your Raspberry Pi software is now up to date. You should run those commands periodically to make sure you are always running the latest software.

Shutdown and Restart your Raspberry Pi

Occasionally you will need to restart your system. You may need to do this after adjusting configuration files, updating your system, or to ensure your system is working as expected. To reboot your Raspberry Pi, run the following command.

sudo reboot

Your system will now perform a complete reboot. If you are connected to your terminal via SSH, you will need to reconnect after a few minutes.

So what if you’re done for the day and it is time to power down your system until the next time you are ready to work with it. You can use the below command to do just that. In this command the -h flag is used to ensure a proper system shutdown by stopping all running processes. We also use now in order to signify that the system needs to shutdown immediately.

sudo shutdown -h now

Once you run this command, your Raspberry Pi should shutdown properly.

See which Processes are Using the Most Resources

If you run into a situation where you need to view what is running on your system to determine what resources are being used, you can use the htop command by typing the below command and hitting enter on your keyboard.

htop

When this command is ran, you will see a screen similar to the screenshot below.

19 Simple Raspberry Pi Terminal Commands for Beginners 1

In the top left hand corner, you can see your process and memory load at a glance. In the top right, you will be able to determine the systems load average and uptime. In the center of the screen you will a list of running processes in a table that will allow you to diagnose any performance problems you may be experiencing. If you want to quit and return to the terminal type the q key.

More information about the htop command can be found here.

Working with The Raspberry Pi File System

Working with the Raspberry Pi file system is easy to get the hang of once you understand the basic commands.

List all files in a directory

To list all of the file in a directory use the following command.

ls

When you run the command, the output will look similar to the test snippet below.

pi@Pi:/ $ ls
bin   dev  home  lost+found  mnt  proc  run   srv  tmp  var
boot  etc  lib   media       opt  root  sbin  sys  usr

If you would like a more organized list, you can add the -l flag. The command is below.

ls -l

This will output an organized list as seen below.

pi@Pi:/ $ ls -l
total 72
drwxr-xr-x   2 root root  4096 Apr 27 12:52 bin
drwxr-xr-x   5 root root  3584 Dec 31  1969 boot
drwxr-xr-x  16 root root  3760 Apr 12 11:17 dev
drwxr-xr-x  83 root root  4096 Apr 27 12:53 etc
drwxr-xr-x   3 root root  4096 Feb  5 10:47 home
drwxr-xr-x  16 root root  4096 Feb  5 10:50 lib
drwx------   2 root root 16384 Feb  5 11:01 lost+found
drwxr-xr-x   2 root root  4096 Feb  5 10:42 media
drwxr-xr-x   2 root root  4096 Feb  5 10:42 mnt
drwxr-xr-x   4 root root  4096 Feb 17 04:27 opt
dr-xr-xr-x 146 root root     0 Dec 31  1969 proc
drwx------   4 root root  4096 Feb 17 05:04 root
drwxr-xr-x  26 root root   840 Apr 27 12:53 run
drwxr-xr-x   2 root root  4096 Apr 27 12:52 sbin
drwxr-xr-x   2 root root  4096 Feb  5 10:42 srv
dr-xr-xr-x  12 root root     0 Dec 31  1969 sys
drwxrwxrwt   8 root root  4096 Apr 27 13:16 tmp
drwxr-xr-x  11 root root  4096 Feb 17 04:27 usr
drwxr-xr-x  11 root root  4096 Feb  5 11:02 var

Change to a different directory

In order to change your working directory you will use the cd, or “change directory” command as outlined below. Replace [location] with the name of the folder that you would like to “change” to.

cd [location]

Once you change into a folder, you can easily go back to the previous directory by typing the following command.

cd -

If you are in the /usr/bin/tmp directory and would like to move up a level to the /usr/bin/ directory you can run the following command.

cd ..

Create a Folder

When you need to create a folder on your Raspberry Pi, you can use the mkdir command. Use the command below to make a new folder. Remember to replace [newfolder] with the name of the folder that you would like to create.

mkdir [newfolder]

Once the command is completed, you can view the folder by using the ls command.

Create a New File

If you would like to create a new file on your Raspberry Pi, you can use the touch command. The command below will create a new blank file on your system. Remember to replace [filename.txt] with the name of the file that you want to create.

touch [filename.txt]

Once the command is complete, you can use the ls command to view the directory to see if the file is listed. If you would like to edit your new file, you can use the nano command. More information about nano here.

Copy a File

Copying a file on your Raspberry Pi is just as easy as the other commands. If you need to copy a file, you can use the cp (copy file) command. Use the command below but replace [filename] with the name of the you would like to copy. Replace [newfilename] with the new name of the copied file. The names cannot be the same unless you choose to put your copied file into a different directory.

cp [filename] [newfilename]

View File

To view the contents of a file on your Raspberry Pi, you can fun the command below. Replace [filename] with the name of the file that you would like to view.

cat [filename]

This command is useful for when you want to view the contents of a file without editing it. Once this command is ran, you should be presented with the contents of the file.

Copy a Folder

Copying a folder on your Raspberry Pi uses the same cp command. The -r flag is used to ensure that it is recursive. Use the command below to copy a folder. Replace [foldername] with the name of folder that you want to copy and [newfoldername] with the name of the new folder that you are creating.

cp -r [foldername] [newfoldername]

Once this is completed, you will have made a copy of a folder and all of it’s contents. You can use the ls command to verify.

Delete a File

To delete a file the rm (remove) command is used. Use the below command to delete a file. Replace [file] with the name of the file that you would like to remove from your Raspberry Pi.

rm [file]

After you run the command you can use the ls command to verify that the file is deleted.

Delete a Folder

You can also use the rm command to delete a directory. The -r flag is added to ensure that all files within the directory get deleted as well. Use the below command to delete a folder from your Raspberry Pi and replace [folder] with the name of the folder that you would like to delete.

rm -r [folder]

One the command completes, you can use the ls command to verify that the folder has been deleted.

Find a File or Folder

If you’ve lost a file you can find it you can use the find command. This command will search your entire system for a file or folder that matches what you are looking for. Use the below command to find a file on your Raspberry Pi. Remember to replace [filename] with the name of the file that you are are looking for.

find / [filename]

Once the command finishes running, you will be presented with a list of files and folders that match the name of the file you are looking for.

Conclusion

After using these Raspberry Pi terminal commands, you should be able to confidently navigate the file system and configuration of your Pi. More posts about the Pi and applications ran on the Pi can be found here. If you have any questions or suggestions, please leave a comment below.

The post, 19 Simple Raspberry Pi Terminal Commands for Beginners, first appeared on Codeopolis.