Skip to content

Bash is a command-line shell commonly used on Linux systems. It allows you to interact with your computer by entering commands into a terminal.

On Raspberry Pi OS, Bash is available by default.

When you open a terminal, Bash displays a command prompt indicating that it is ready for you to enter a command.

The appearance of the prompt varies between systems and can be customized. For example, a prompt might display information such as your username, hostname, or current directory. This could look like:

username@hostname:~ $

Type a command and press Enter to run it.

A path describes the location of a file or directory.

An absolute path starts from the root directory /:

/home/username/Documents

A relative path starts from your current directory:

Documents/example.txt

The following have special meanings:

Path Meaning
. Current directory
.. Parent directory (one directory above your current directory)
~ Your home directory
/ Root directory

Your current directory is the directory you are currently working in.

To see your current directory:

Terminal window
pwd

To see the files and directories inside it:

Terminal window
ls

To include hidden files:

Terminal window
ls -a

Use cd to move to a different directory:

Terminal window
cd directory

For example:

Terminal window
cd Documents

Create a directory with mkdir:

Terminal window
mkdir example

Remove an empty directory:

Terminal window
rmdir example

Display the contents of a text file:

Terminal window
cat example.txt

For longer files, you can use:

Terminal window
less example.txt

Use the arrow keys to move through the file and press q to quit.

There are multiple text editors available in the terminal. One example is Vim. You can open a text file in Vim with:

Terminal window
vim example.txt

See the Vim reference for the commands needed to edit, save, and quit.

Copy a file:

Terminal window
cp source destination

For example:

Terminal window
cp example.txt backup.txt

Move a file:

Terminal window
mv example.txt Documents/

mv can also be used to rename a file:

Terminal window
mv example.txt renamed.txt

Remove a file:

Terminal window
rm example.txt

Some system changes require administrator privileges. Use sudo before a command to run it with elevated privileges:

Terminal window
sudo command

For example:

Terminal window
sudo apt update

You may be asked for your password.

To interrupt a command that is currently running:

Ctrl+C

This is useful when a command is hanging or when you need to stop a running program.

Press Tab while typing to automatically complete commands, file names, and directory names when possible.

For example, if the current directory contains a directory named Documents, you could type:

Terminal window
cd Doc

Then press Tab to complete it:

Terminal window
cd Documents/

If there is more than one possible match, press Tab again to display the available options.

Use the Up and Down arrow keys to move through commands you have previously entered.

To display your command history:

Terminal window
history

This displays previously entered commands along with their history numbers.

Command Action
pwd Show where you are
ls Show what’s here
cd directory Change directory
mkdir name Create a directory
cat file Display a file
vim file Edit a file using Vim
rm file Remove a file
sudo command Run a command with elevated privileges
Ctrl+C Stop a running command