20 Handy Raspberry Pi Terminal Commands for Beginners

Get to grips with the terminal using these handy commands

Something many people struggle with when they first starting to use the Raspberry Pi computer is the terminal.

You may go from being a happy Windows GUI user to a retro-looking black and green screen with no buttons or anything to double-click. This can be scary stuff as you've been using a GUI since your first PC.

But, there are many little tricks and commands that can help users gain the confidence to use the system.

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.

of 20

[sudo apt-get update] - Update Package Lists

Update Command in the Terminal

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.

of 20

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

Upgrade command in the terminal

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.

of 20

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

Clean command in the terminal

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.

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

of 20

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

The Raspberry Pi Configuration Tool

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 like a ‘settings’ window, allowing you to set languages, time/date, enable the camera module, overclock the processor, enable devices, change passwords and many 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.

of 20

[ls] - List Directory Contents

ls command in the terminal

Richard Saville

The Linux ‘directory’ is the same as a ‘folder’ in Windows. That’s something you may have to get used (being a Windows user) to.

There is, 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 color-coded for the different items.

of 20

[cd] - Change Directories

cd command in the terminal

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, similar to the 'back' button.

of 20

[mkdir] - Create a Directory

mkdir command in the terminal

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'.

of 20

[rmdir] - Remove a Directory

rmdir command in the terminal

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.

of 20

[mv] - Move a File

Move files with the "mv" command

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'.

of 20

[tree -d] - Show a Tree of Directories

The Tree command is a handy way to view the structure of your directories

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.

of 20

[pwd] - Show the Current Directory

Using 'pwd' can help you when you start feeling a bit lost!

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. 

of 20

[clear] - Clearing the Terminal Window

clear command in the terminal

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.

of 20

[sudo halt] - Shut Down your Raspberry Pi

Shut down your Raspberry Pi safely with the 'half' command

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.

of 20

[sudo reboot] - Restart your Raspberry Pi

Restart your Pi using reboot in the terminal

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.

of 20

[startx] - Start the Desktop Environment (LXDE)

startx command in the terminal

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.

of 20

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

ifconfig can give you useful network information

Richard Saville

There are a lot of scenarios that may require you to know the IP address of your Raspberry Pi. Many use it when configuring an SSH session to remotely access their 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.

of 20

[nano] - Edit a File

Nano in the terminal, a preferred text editor for Raspberry Pi

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.

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.

of 20

[cat] - Shows The Contents of a File

cat in the terminal

Richard Saville

While 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'.

of 20

[rm] - Remove a File

The rm command in the terminal helps remove files easily

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'.

of 20

[cp] - Copy a File or Directory

The cp command in the terminal helps copy files

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.