Computers, Laptops & Tablets Accessories & Hardware 137 137 people found this article helpful 20 Handy Raspberry Pi Terminal Commands for Beginners Get to grips with the terminal using these handy commands By Richard Saville Writer Richard Saville is a former Lifewire writer and computer enthusiast who has invented several add-on boards for Raspberry Pi and has been published in MagPi and other outlets. our editorial process Facebook Twitter Richard Saville Updated November 12, 2019 Accessories & Hardware Raspberry Pi Keyboards & Mice Monitors Cards HDD & SSD Printers & Scanners Tweet Share Email 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. 01 of 20 [sudo apt-get update] - Update Package Lists 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 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 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. 04 of 20 [sudo raspi-config] - 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. 05 of 20 [ls] - List Directory Contents 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. 06 of 20 [cd] - Change Directories 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. 07 of 20 [mkdir] - Create a Directory 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 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 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 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 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 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 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 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) 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 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. 17 of 20 [nano] - Edit a File 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. 18 of 20 [cat] - Shows The Contents of a File 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'. 19 of 20 [rm] - Remove a File 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 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.