VMware ESXi and vSphere Cluster Management
Useful Raspberry Pi Terminal Commands for Navigating Directories and Working with Files
Learn essential Raspberry Pi OS terminal commands including ls, pwd, cd, echo, and whoami, with safe navigation examples and troubleshooting tips.
The Raspberry Pi OS terminal is a text-based interface for entering commands and viewing their output. It lets you inspect and control the Linux system without using graphical windows and menus.
The program that reads your commands and runs them is called the shell. When the shell is ready for input, it displays a command prompt. Type a command after the prompt and press Enter.
pwd
The prompt itself can vary depending on the shell and its configuration. It may show the active username, Raspberry Pi hostname, and part or all of the current directory. Do not rely on the prompt alone to identify your location: use pwd when you need confirmation.
Directories, files, and paths
A directory is a filesystem container, commonly called a folder. It can contain files and other directories. A file is a named unit of stored data, such as a document, image, program, or configuration file.
The current working directory is the directory in which the shell is currently operating. Many commands use it as their default location. For example, ls lists the current directory unless you provide another path.
A path is the filesystem address of a file or directory. Linux supports two important kinds of paths:
- An absolute path gives the complete address from the root directory. It begins with
/, such as/opt. - A relative path is interpreted from the current working directory. For example,
Documentsmeans a directory namedDocumentsinside the current directory.
The root directory is the top-level directory in the Linux filesystem and is written as /. It is different from the administrator account, which is also sometimes called root.
Your home directory is your default personal directory. The notation ~ represents the home directory of the active user. The notation . means the current directory, and .. means the parent directory, one level above the current directory.
List directory contents with ls
The ls command shows files and directories. With no argument, it lists entries in the current working directory.
ls
You can also give ls a path to inspect a different directory without moving into it:
ls /opt
To see more information about each entry, use the long listing option, written as -l:
ls -l
A long listing commonly resembles this:
drwxr-xr-x 2 pi pi 4096 Aug 19 10:30 Documents
-rw-r--r-- 1 pi pi 128 Aug 19 10:25 notes.txt
The exact dates, usernames, sizes, and names will vary. The first field shows the file type and permissions. The remaining fields show metadata such as link count, owner, group, size, modification date and time, and name.
For this beginner lesson, focus on using the long listing to identify names, ownership, size, dates, and the general permissions field. A directory normally begins with d in the first field, while a regular file normally begins with -.
Show your current location with pwd
The pwd command means “print working directory.” It displays the full absolute path of the current working directory.
pwd
For example, the output might be:
/home/pi
Use pwd before listing, creating, or modifying files when you are not certain where you are. This simple check prevents many mistakes caused by assuming that the shell is in a different directory.
Change directories with cd
The cd command changes the current working directory. Follow it with a path.
Use an absolute path
To move directly to the system directory /opt, use:
cd /opt
pwd
ls
The pwd command should show /opt. The following ls then lists the contents of that directory.
Use a relative path
Suppose the current directory contains a child directory named Documents. Enter it with:
cd Documents
pwd
Because Documents does not begin with /, the shell looks for it inside the current working directory. The same navigation could be written explicitly as:
cd ./Documents
Move to the parent or home directory
Move one level upward with cd ..:
cd ..
pwd
Return to the active user's home directory with either cd or cd ~:
cd
pwd
cd ~
pwd
Both forms take you to the home directory of the account running the shell. After changing directories, the prompt may display a different location, but use pwd when you need a definite answer.
Display text with echo
The echo command writes supplied text to the terminal. It is useful for displaying a message, confirming a value, testing shell behavior, and producing simple output.
echo "Hello from my Raspberry Pi"
The quotation marks keep a multiword message together as one quoted piece of text. For simple output, this also works:
echo Raspberry Pi
Quoting is the safer habit when text contains spaces or shell-special characters. For example:
echo "The current directory will be checked next"
Identify the active user with whoami
The whoami command displays the username of the account currently running the shell.
whoami
The result might be pi or another username, depending on how Raspberry Pi OS was configured. The active user matters because file ownership and permissions determine which files the account can read, change, or enter.
Run whoami when an access error is unexpected. You can compare its result with a username shown in the command prompt, if the prompt includes one.
Essential terminal commands
Practical command sequences
Confirm a starting location and inspect it
Use this sequence when you first open a terminal or feel unsure about your location:
pwd
ls
ls -l
pwdprints the current directory.lsshows the names of entries there.ls -ladds metadata for the same location.
Navigate to a known system directory
cd /opt
pwd
ls
This uses an absolute path, verifies the result, and then inspects the directory.
Navigate through child and parent directories
From a directory containing a child folder named Documents:
ls
cd Documents
pwd
cd ..
pwd
cd ~
pwd
This sequence lists the available entries, enters the child directory, returns to its parent, and then goes home.
Print a message and check the account
echo "Hello from my Raspberry Pi"
whoami
The first command produces text. The second identifies the account that produced it.
Safe command-line habits
- Run
pwdbefore operating on files if you are not completely sure of your location. - Run
lsbefore entering or acting on an unfamiliar directory. - Remember that Linux names and paths are case-sensitive.
Documents,documents, andDOCUMENTScan be different names. - Use the Tab key for completion when available. Type the beginning of a directory name and press Tab to complete a matching name or show possible matches.
- Read the command output carefully. Normal output usually reports the requested information; error messages explain why the request could not be completed.
- When a command produces an unexpected result, stop and verify the path with
pwdrather than immediately trying more commands.
Troubleshooting common problems
“No such file or directory” after cd
This error usually means the path was mistyped, the assumed current directory is wrong, or the letter case does not match the real name.
pwd
ls
cd ExactDirectoryName
Use pwd to confirm where you are and ls to see the names that actually exist. You can also use an absolute path or Tab completion.
ls does not show the expected files
You may be in a different directory from the one you intended, or you may have listed the current directory instead of the target directory.
pwd
ls
ls /path/to/the/intended-directory
ls -l
Replace the example target with the path you intend to inspect. The long listing can provide additional context about the entries.
“Permission denied” after cd
This message means the active user does not have permission to enter that directory. Check the account first:
whoami
Choose a directory that the account is allowed to access. Do not change permissions simply to remove the error unless you understand how that change affects system security and other users.
echo displays unexpected spacing or split text
Text containing spaces should be enclosed in quotation marks when quoting matters:
echo "sample message"
Without appropriate quoting, the shell can treat separate words as separate arguments. For basic echo output, quoting the complete message is a reliable habit.
You are unsure whether cd worked
The prompt may not show the full path. Verify the change directly:
cd /opt
pwd
If the output is /opt, the directory change succeeded.
What to learn next
Once these commands are comfortable, useful next steps include creating directories with mkdir, creating empty files with touch, copying and moving items with cp and mv, deleting items with rm, and viewing file contents with cat or less. You can also study Linux permissions and ownership, safe use of sudo, command history, Tab completion, the nano editor, and redirecting command output to files.
For a compact reference, return to Useful Terminal Commands.