KevsRobots Learning Platform
12% Percent Complete
By Kevin McAleer, 4 Minutes
Navigating the filesystem is a fundamental skill when working with the command line. In this lesson, you’ll learn how to use basic commands to find your way around the Raspberry Pi OS filesystem.
pwd
, ls
, cd
, clear
and history
commands.The Linux filesystem is organized in a hierarchical structure, starting from the root directory (/
). Every file and directory is nested within this structure. Here’s a basic overview:
/
: Root directory, the top level of the filesystem./home
: Contains user directories, like /home/pi
for the Raspberry Pi user./etc
: Configuration files for the system./var
: Variable data, such as logs and temporary files./usr
: User programs and data./bin
: Essential system binaries./lib
: Shared libraries./opt
: Optional software packages./tmp
: Temporary files.pwd
CommandThe pwd
(print working directory) command displays the current directory you are in. This is useful to know where you are in the filesystem.
pwd
ls
CommandThe ls
(list) command lists the contents of a directory. You can use it to see files and subdirectories within your current directory.
ls
You can also use options with ls to get more detailed information:
ls -l
cd
CommandThe cd
(change directory) command allows you to navigate between directories. For example, to move into the Documents
directory, you would type:
cd Documents
To return to the home directory, simply type:
cd $HOME
To back up one directory, use:
cd ..
/
, e.g., /home/pi/Documents
.Documents
if you are in /home/pi
.To clear the terminal screen, you can use the clear
command:
clear
This will clear the terminal screen, making it easier to read the output of new commands.
The history
command is a useful tool that shows you a list of the commands you’ve previously run in the terminal. This can help you remember commands you’ve used before or quickly repeat them without typing them out again.
To see your command history, simply type:
history
This will display a numbered list of your recent commands.
You can easily re-run a command from your history by using the !
symbol followed by the command number. For example, if the command you want to repeat is number 42 in the history list, you can type:
!42
This will execute the command exactly as you ran it before.
Repeating the Last Command: If you want to run the very last command again, you can use !!
:
!!
This is handy if you forgot to use sudo
and want to rerun the command with it.
Searching Your History: You can search for a previous command by typing Ctrl + r
and then start typing part of the command. This will show you the most recent match from your history, which you can then execute by pressing Enter
.
In this lesson, you learned how to navigate the filesystem using the pwd
, ls
, cd
, clear
and history
commands, and you now understand the difference between absolute and relative paths. These are essential skills for working efficiently in the command line.
You can use the arrows ← →
on your keyboard to navigate between lessons.