Useful Raspberry Pi Terminal Commands
Learn essential Raspberry Pi OS terminal commands for listing files, checking your location, changing directories, displaying text, and identifying the active user.
The terminal is a text-based environment for interacting with Raspberry Pi OS. Instead of clicking buttons and folders, you type commands at a prompt and press Enter. The operating system runs the command and displays its result.
A shell is the command interpreter that reads what you type and runs it. Most commands use the current working directory: the folder the shell currently treats as its default location. Linux commands and paths are case-sensitive, so Documents, documents, and DOCUMENTS can refer to different names.
If you need a reminder about opening and using the terminal, see Terminal In Raspbian.
Understanding the command prompt
The command prompt is the text shown by the shell when it is ready to accept a command. A typical prompt may contain the active username, the Raspberry Pi's device name, and the current directory. For example:
pi@raspberrypi:~ $In this example, pi is the user, raspberrypi is the device name, and ~ is a shorthand display for that user's home directory. The dollar sign indicates that the shell is ready for input. The exact appearance depends on your account and configuration.
The displayed location changes when you move between directories. After cd /opt, a prompt might look like this:
pi@raspberrypi:/opt $The prompt is useful, but use pwd when you need an unambiguous complete path.
Finding your location with pwd
pwd means “print working directory.” It prints the complete path of the shell's current working directory.
pwdA result such as the following tells you exactly where commands that use relative paths will operate:
/home/piRun pwd before working with files if you are unsure of your location. It is also a useful confirmation after using cd.
Listing files and directories with ls
A directory is a folder that can contain files and other directories. The ls command displays the items in a directory.
List the current directory
With no argument, ls lists the contents of the current working directory:
lsThe exact output depends on which files and folders exist in that location.
List another directory
Supply a path to inspect a different directory without moving there:
ls /optThis lists the contents of /opt while leaving your current working directory unchanged.
Use a long listing
The -l option requests a long listing, which provides more information about each item:
ls -lAt a beginner level, the columns commonly show:
- Permissions: rules controlling whether users may read, modify, or execute an item.
- Ownership: the user and group associated with the item.
- Size: the item's size, usually in bytes for this display.
- Modification time: when the item was last changed.
- Name: the file or directory name.
Long listings are especially useful when investigating ownership or access problems.
Changing directories with cd
The cd command changes the shell's current working directory. A path identifies a filesystem location.
Absolute and relative paths
An absolute path begins at the filesystem root. The filesystem root is the top-level Linux directory, written as /. For example:
cd /opt
pwdThe first command moves directly to /opt, regardless of your starting location. The second confirms the change.
A relative path is interpreted from the current working directory. For example, if pwd reports /home/pi and a directory named projects is inside it, you can use:
cd projectsThis means “enter the projects directory located here.” Use ls to check that the name exists before entering it.
Common navigation shortcuts
| Notation or form | Meaning | Example |
|---|---|---|
/ | Filesystem root, the top-level directory | ls / |
. | The current directory | ls . |
.. | The parent directory, one level above the current directory | cd .. |
| Absolute path | A location beginning at the root | cd /opt |
| Relative path | A location interpreted from the current directory | cd projects |
cd with no path | The active user's home directory | cd |
To move up one level and inspect the new location:
cd ..
pwd
lsA single period means the current directory. It is often useful when a command requires an explicit path, but cd . does not move you anywhere:
cd .Use cd without an argument to return to the home directory for the active account:
cd
pwdHandling spaces in directory names
The shell normally treats spaces as separators between arguments. If a directory is named My Projects, quote the name so the shell treats it as one path:
cd "My Projects"You can also escape the space with a backslash:
cd My\ ProjectsAfter changing directories, verify the destination with pwd or inspect it with ls.
Displaying text with echo
The echo command writes the supplied text to the terminal:
echo Hello, Raspberry Pi!Its output is:
Hello, Raspberry Pi!echo is also commonly used to check the value of a shell variable or to produce text in a simple script. Those uses become more useful as you learn basic shell scripting.
Identifying the active account with whoami
The whoami command prints the username of the account running the current shell:
whoamiThe result might be pi, another account name, or a username you created. This is the active user. It is different from the device name shown in a typical prompt: the username identifies the account, while the device name identifies the Raspberry Pi on the network.
The active user affects ownership and permissions. If you cannot read or modify an item, use whoami to identify the account and ls -l to inspect the item's owner and permissions.
Essential command reference
| Command | Purpose | Typical use | Key notes |
|---|---|---|---|
ls | List directory contents | ls | Uses the current directory when no path is supplied. |
ls -l | Show a detailed listing | ls -l | Displays permissions, ownership, size, time, and name. |
pwd | Print the current location | pwd | Shows the complete path. |
cd /opt | Change directory | cd /opt | Uses an absolute path. |
cd .. | Move to the parent directory | cd .. | Moves up one level. |
cd | Go to the home directory | cd | Uses the active user's home directory. |
echo | Display text | echo Hello | Writes supplied text to the terminal. |
whoami | Show the active username | whoami | Helps explain permission behavior. |
Safe beginner terminal habits
- Read the complete command before pressing Enter. A small spelling or path difference can change its result.
- Remember that commands may act on the current working directory, especially when you use relative paths.
- Press Tab to complete directory and file names. Tab completion reduces typing and helps prevent spelling and case errors.
- Press the Up Arrow key to review and reuse earlier commands from shell history.
- Do not use elevated privileges unless a task explicitly requires them. Running a command with extra privileges can affect protected system files and directories.
- Use
pwdandlsto confirm your location before changing or managing files.
Troubleshooting common problems
cd says that a directory does not exist
Common causes include a misspelled path, incorrect letter case, an unexpected current directory, or spaces that were not quoted. Check the context and available names:
pwd
lsThen try Tab completion, use an absolute path, or quote a name containing spaces:
cd "My Projects"ls shows unexpected contents
You may be in a different directory than you assumed, or you may have listed the current directory instead of the intended one. Run pwd, then either supply an explicit path or move to the intended location:
pwd
ls /opt
cd /opt
lsAn item is not visible with normal ls
Some items are hidden because their names begin with a period. Hidden-item options exist, but the important beginner lesson is that a normal listing does not always show every item in a directory.
You cannot access or modify an item
The active account may lack the required permissions, or the item may be in a protected system location. Identify the account and inspect the listing:
whoami
ls -lAvoid treating elevated privileges as the default solution. First understand which account owns the item and which permissions are granted.
Practice sequence
Run the following sequence and observe how the location and output change:
pwd
ls
whoami
cd /opt
pwd
ls
cd ..
pwd
cd
echo Hello, Raspberry Pi!This combines location checking, listing, navigation, account identification, and text output. For the next steps, explore Directory Management and File Management. For permission-specific work, see Change Password only when relevant to account administration, and learn about safer privileged commands separately.