Computers, Laptops & Tablets Accessories & Hardware 142 142 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 on June 27, 2020 Accessories & Hardware Raspberry Pi The Quick Guide to Webcams Keyboards & Mice Monitors Cards HDD & SSD Printers & Scanners Tweet Share Email Something many people struggle with when they begin using the Raspberry Pi computer is the terminal. The terminal may go from a Windows GUI to a retro-looking black and green screen with no buttons to double-click. However, there are many tricks and commands that can help you gain the confidence to use the system. Start with the following commands to 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 begin with. 01 of 20 sudo apt update: Update Package Lists This is the first stage in updating your Raspberry Pi. See the next two items in this list for the other steps. sudo apt update This command downloads package lists from the repositories and retrieves information on the newest versions of these packages and any dependent packages. It doesn't update in the traditional sense. Instead, it's a required step in the overall update process. 02 of 20 sudo apt upgrade: Download and Install Updated Packages This command follows the previous item, where the package list was updated. sudo apt upgrade With the updated package list in place, the sudo apt upgrade command looks at what packages are currently installed. It then looks at the latest package list (that was previously upgraded) and installs any new packages that aren't at the latest version. 03 of 20 sudo apt clean: Clean Old Package Files This is the final stage in the update and upgrade process and isn't always essential if you have plenty of disk space. sudo apt clean This 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 low on space or want to clean up the system. 04 of 20 sudo raspi-config: The Raspberry Pi Configuration Tool This is one of the first steps you take when you first start using a Raspberry Pi. Use this command to make sure it's set up for your language, hardware, and projects. The configuration tool is like a settings window. It allows you to set languages, time and date, enable the camera module, overclock the processor, enable devices, change passwords, and other options. To access this, type the command below and press Enter. sudo raspi-config Depending on what you change, you may be prompted to reboot the Pi. 05 of 20 ls: List Directory Contents The Linux directory is the same as a folder in Windows. There isn't an explorer in the terminal. To see what's inside the directory you're in at any given time, type: ls Then, press 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 If you want to go to a certain directory, use the cd command. If the directory you're in has directories inside it, use cd directoryname (replace directoryname with the name of the directory you want to view). For example: cd Documents If the directory is somewhere else in the file system, enter the path after the command, such as: cd /home/pi/Documents 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 If you need to create a new directory within an existing direction, use the mkdir command. This is the New > Folder equivalent of the terminal world. To make a new directory, add the name of the directory after the command, such as mkdir new_directory. For example: mkdir /home/pi/Documents/projects 08 of 20 rmdir: Remove a Directory When you want to delete a directory, use rmdir followed by the directory name. rmdir /home/pi/Documents/projects For example, rmdir directory_name removes the directory directory_name. The directory must be empty to perform this command. 09 of 20 mv: Move a File Move files between directories by using the mv command. To move a file, enter mv followed by the file name and then the destination directory. For example: mv my_file.txt /home/pi/destination_directory This command moves the my_file.txt file to /home/pi/destination_directory. 10 of 20 tree -d: Show a Tree of Directories After creating new directories, you might miss the visual folder structure view of the Windows file explorer. When you can't see a visual layout of your directories, things can get confusing. Use the tree -d command to display directories in a tree-like layout within the terminal. Type this command and press Enter: tree -d 11 of 20 pwd: Show the Current Directory Another handy command to help you when you're lost is the pwd command. Use this command when you want to know where you are in the directory structure: pwd Enter pwd at any time to display the current directory path you're in. 12 of 20 clear: Clear the Terminal Window As you start to get the hang of the terminal, you'll notice that it can become cluttered. After a few commands, you leave a trail of text on the screen, which for some, can be annoying. clear To wipe the screen clean, use the clear command. The screen will be cleared and ready for the next command. 13 of 20 sudo halt: Shut Down a Raspberry Pi Turning off a 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 damage the card. To shut down the Pi properly, use: sudo halt After the final flashes from the Pi's LEDs, remove the power cable. 14 of 20 sudo reboot: Restart a Raspberry Pi Like the shutdown command, if you want to reboot your Raspberry Pi safely, use the reboot command. For example: sudo reboot Run the above command to restart the Pi. 15 of 20 startx: Start the Desktop Environment (LXDE) If you set your Pi to always start in the terminal, here's how to start the desktop if you need to use it. startx Use startx to start the LXDE (Lightweight X11 Desktop Environment). This command doesn't work over an SSH session. 16 of 20 ifconfig: Find a Raspberry Pi's IP Address There are several scenarios that may require you to know the IP address of your Raspberry Pi. For example, when configuring an SSH session to access a Pi remotely. ifconfig To find your IP address, type ifconfig into the terminal and press Enter. You can also use hostname -I to find the IP address. 17 of 20 nano: Edit a File Linux has several text editors, and some people prefer using one over the other for various reasons. nano my_file.txt To edit a file, type nano followed by the file name, such as nano myfile.txt. When your edits are complete, press Ctrl+X to save the file. 18 of 20 cat: Show the Contents of a File While you can use nano to open a file for editing, there is a separate command to 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 Removing files is easy on the Raspberry Pi, and is something you will do as you make versions of Python files while you troubleshot code. To remove a file, use the rm command followed by the filename. For example: rm myfile.txt 20 of 20 cp: Copy a File or Directory When you need to make a copy of a file or directory, use the cp command. To make a copy of a 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 copies folder_one into folder_two.