20 Handy Raspberry Pi Terminal Commands For Beginners

Get to grips with the terminal using these handy commands

Something I really struggled with when I first started using the Raspberry Pi was the terminal.

I went from being a happy Windows GUI user to a retro-looking black and green screen with no buttons or anything to double-click. Scary stuff when you've been using a GUI since your first PC.

These days I’m much more familiar with the terminal, using it for pretty much all of my Raspberry Pi projects in one way or another. I found out lots of little tricks and commands along the way that helped me gain this confidence, and I’m sharing these with you to help you get started with the Pi.

There isn’t anything advanced or groundbreaking here - just basic everyday commands that will help you navigate and undertake simple tasks with your Raspberry Pi from a terminal window. Over time you'll find more, but this is a good core set to kick off with.

01
of 20

[sudo apt-get update] - Update Package Lists

update command in the terminal
The update command makes sure your package lists are current. Image: Richard Saville

This is the first stage in updating your Raspberry Pi (see the next two items in this list for the other steps).

The 'sudo apt-get update' command downloads package lists from the repositories and grabs information on the newest versions of these packages and any dependent ones as well.

So it doesn't really do any actual updating in the traditional sense, it's more of a required step in that overall process.

02
of 20

[sudo apt-get upgrade] - Download and Install Updated Packages

Upgrade command in the terminal
The upgrade command downloads and installs updates packages. Image: Richard Saville

This command follows on from the previous item where we updated our package list.

With our updated package list in place, the 'sudo apt-get upgrade' command will look at what packages are currently installed, then look at the latest package list (that we just upgraded), and then finally install any new packages that aren't at the latest version.

03
of 20

[sudo apt-get clean] - Clean Old Package Files

Clean command in the terminal
The clean command removes old package downloads, saving you storage space. Image: Richard Saville

The final stage in the update and upgrade process, and one that isn't always essential if you have plenty of disk space.

The 'sudo apt-get clean' command deletes the redundant package files (.deb files) that are downloaded as part of the update process.

A handy command if you're tight on space or just want to have a good clean up.

04
of 20

[sudo raspi-config] - The Raspberry Pi Configuration Tool

raspi-config in terminal
The Raspberry Pi Configuration Tool. Image: Richard Saville

This should be one of the first steps you take when you first start using a Raspberry Pi, to make sure it's set up for your language, hardware, and projects.

The configuration tool is a bit like a ‘settings’ window, allowing you to set languages, time/date, enable the camera module, overclock the processor, enable devices, change passwords and lots of other options.

You can access this by typing ‘sudo raspi-config’ and then hitting enter. Depending on what you change, you may be prompted to reboot your Pi afterward.

05
of 20

[ls] - List Directory Contents

ls command in the terminal
The 'ls' command will list contents of a directory. Image: Richard Saville

In Linux a ‘directory’ is the same as a ‘folder’ in Windows. That’s something I had to get used (being a Windows person) to so I wanted to point that out up front.

There’s, of course, no explorer in the terminal, so to see what’s inside the directory you’re in at any given time, just type in ‘ls’ and hit enter.

You will see every file and directory within that directory listed, and usually colour-coded for the different items.

06
of 20

[cd] - Change Directories

cd command in the terminal
Use 'cd' to change directories. Image: Richard Saville

If you want to jump to a certain directory, you can use the 'cd' command.

If the directory you're already in has directories inside it, you can simply use 'cd directoryname' (replacing 'directoryname' with the name of your directory).

If it's somewhere else in your file system, just enter the path after the command, such as 'cd /home/pi/directoryname'.

Another handy use of this command is 'cd ..' which takes you back one folder level, a bit like a 'back' button.

07
of 20

[mkdir] - Create a Directory

mkdir command in the terminal
Create new directories with 'mkdir'. Image: Richard Saville

If you need to create a new directory within the one you’re already in, you can use the ‘mkdir’ command. This is the 'new > folder' equivalent of the terminal world.

To make a new directory, you just need to add the name of the directory after the command, such as 'mkdir new_directory'.

08
of 20

[rmdir] - Remove a Directory

rmdir command in the terminal
Remove directories with 'rmdir'. Image: Richard Saville

You've learned how to create a new directory, but what if you want to delete one?

It's a very similar command to remove a directory, just use 'rmdir' then the directory's name.

For example 'rmdir directory_name' will remove the directory 'directory_name'. It's worth noting that the directory must be empty to perform this command.

09
of 20

[mv] - Move a File

mv command in the terminal
Move files with the 'mv' command. Image: Richard Saville

Moving files between directories is achieved by using the 'mv' command.

To move a file, we use 'mv' followed by the file name and then the destination directory.

An example of this would be 'mv my_file.txt /home/pi/destination_directory', which would move the 'my_file.txt' file to '/home/pi/destination_directory'.

10
of 20

[tree -d] - Show a Tree of Directories

tree command in the terminal
Tree is a handy way to view the structure of your directories. Image: Richard Saville

After creating a handful of new directories, you might be missing the visual folder structure view of the Windows file explorer. Without being able to see a visual layout of your directories, things can get confusing fast.

One command that can help make more sense of your directories is 'tree -d'. It displays all of your directories in a tree-like layout within the terminal.

11
of 20

[pwd] - Show the Current Directory

pwd command in the terminal
Using 'pwd' can help you when you start feeling a bit lost!. Image: Richard Saville

Another handy command to help you when you're lost is the 'pwd' command. This is handy if you just want to know where you are at any given moment.

Simply enter 'pwd' at any time to display the current directory path you're in. 

12
of 20

[clear] - Clearing the Terminal Window

clear command in the terminal
Remove screen clutter with the 'clear' command. Image: Richard Saville

As you start to get the hang of the terminal, you'll notice that it can get quite cluttered. After a few commands, you leave a trail of text on the screen which for some of us can be a bit annoying.

If you want to wipe the screen clean, simply use the 'clear' command. The screen will be cleared, ready for the next command.

13
of 20

[sudo halt] - Shut Down your Raspberry Pi

halt command in the terminal
Shut down your Raspberry Pi safely with the 'halt' command. Image: Richard Saville

Turning off your Raspberry Pi safely avoids issues such as SD card corruption. You can get away with a quick pull of the power cord sometimes, but, eventually, you'll kill your card.

To shut down the Pi properly, use 'sudo halt'. After the final flashes from the Pi's LEDs, you can remove the power cable.

14
of 20

[sudo reboot] - Restart your Raspberry Pi

reboot command in the terminal
Restart your Pi using 'reboot' in the terminal. Image: Richard Saville

Similar to the shutdown command, if you want to reboot your Raspberry Pi in a safe way, you can use the 'reboot' command.

Simply type 'sudo reboot' and your Pi will restart itself.

15
of 20

[startx] - Start the Desktop Environment (LXDE)

startx command in the terminal
Start a desktop session using 'startx'. Image: Richard Saville

If you have set your Pi to always start in the terminal, you may be wondering how to start the desktop if you need to use it.

Use 'startx' to start the LXDE (Lightweight X11 Desktop Environment). It should be noted that this will not work over an SSH session.

16
of 20

[ifconfig] - Find Your Raspberry Pi's IP Address

ifconfig command in the terminal
ifconfig can give you useful network information. Image: Richard Saville

There are a lot of scenarios that may require you to know the IP address of your Raspberry Pi. I use it a lot when configuring an SSH session to remotely access my Pi.

To find your IP address, type 'ifconfig' into the terminal and press enter. You can also use 'hostname -I' to find just the IP address on its own.

17
of 20

[nano] - Edit a File

nano in the terminal
My preferred text editor for the Raspberry Pi is nano. Image: Richard Saville

Linux has a number of different text editors, and you'll find that some people prefer using one over the other for various reasons.

My preference is 'nano' mostly because it's the first one I used when I started out.

To edit a file, simply type 'nano' followed by the file name, such as 'nano myfile.txt'. Once your edits are complete, press Ctrl+X to save the file.

18
of 20

[cat] - Shows The Contents of a File

cat in the terminal
Show the contents of a file in the terminal using 'cat'. Image: Richard Saville

Whilst you can use 'nano' (above) to open a file for editing, there is separate command you can use to simply list the contents of a file within the terminal.

Use 'cat' followed by the file name to do this, for example 'cat myfile.txt'.

19
of 20

[rm] - Remove a File

rm command in the terminal
Remove files easily using 'rm'. Image: Richard Saville

Removing files is easy on the Raspberry Pi, and is something you will do a lot of as you make lots of versions of Python files whilst you troubleshot code.

To remove a file, we use the 'rm' command followed by the filename. An example would be 'rm myfile.txt'.

20
of 20

[cp] - Copy a File or Directory

cp command in the terminal
Copy files using 'cp'. Image: Richard Saville

When you need to make a copy of a file or directory, use the 'cp' command.

To make a copy of your file in the same directory, enter the command as 'cp original_file new_file'

To make a copy in a different directory, with the same name, enter the command as 'cp original_file home/pi/subdirectory'

To copy an entire directory (and its contents), enter the command as 'cp -R home/pi/folder_one home/pi/folder_two'. This will copy 'folder_one' into 'folder_two'.

There's Much More To Learn Yet

These 20 commands will help you get started with your Raspberry Pi - updating the software, navigating directories, creating files and generally working your way around. You will no doubt progress from this initial list as you gain confidence, start making projects and generate a need to learn more advanced commands.