Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français
Lire en français

Open a terminal and understand the prompt

By updated

Improve this page

The terminal is your way into Linux. It is where you install a package, read a log or start a service, often on a machine with no graphical interface. This guide assumes a Linux machine, desktop or server, and no experience with the terminal: you open it, read what it displays and type your first commands, in under ten minutes. The history, completion and shortcuts of Bash have their own guide: Getting started with Bash.

What you will learn

  • Open a terminal on a graphical desktop or over SSH
  • Read the prompt and identify the user, the machine and the current directory
  • Tell apart terminal, shell and session
  • Run discovery commands: whoami, pwd, hostname, date
  • Recognise the first error messages
  • Copy and paste safely and leave the terminal cleanly

Terminal, shell, session: three words to tell apart

Three words come up constantly as soon as you talk about the terminal. It is better to tell them apart before typing any command.

WordWhat it is
TerminalThe graphical application (or the SSH window) that displays text
ShellThe program that interprets your commands (Bash, Zsh, Fish…)
SessionThe active connection of a user, from opening (login) to closing (logout)

When you open a terminal, it starts a shell. The shell waits for your commands, runs them and shows you the result. When you close the terminal (or type exit), the session ends.

The diagram follows a command from your keyboard to the screen. Look mainly at each one's role: the terminal only passes on what you type and displays text, whereas the shell is the only one that reads the line and starts the requested program.

Sequence diagram: you type a command then Enter in the terminal. The terminal passes the line on to the shell, which starts the requested program. The program sends its result back to the shell, the shell sends the text back to the terminal, and the terminal displays it.ProgramShellTerminalYoutype a commandthen Enterpasses the line onstarts the programresultsends the text backdisplays the text
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

Open a terminal

On Ubuntu, the keyboard shortcut is Ctrl + Alt + T. It does not always exist on other GNOME distributions: search for "Terminal" in the applications instead.

If you work on Windows, the guide Install WSL2 gives you a Linux terminal in which the commands of this page work.

Once the terminal is open, you see a line of text waiting for your input: that is the prompt.

Understand the prompt

The default Bash prompt on Debian and Ubuntu looks like this:

bob@server:~$

Each part has a precise role:

ElementMeaning
bobName of the logged-in user
@Separator
serverName of the machine (hostname)
:Separator
~Current directory (~ = home directory, /home/bob)
$Regular user (# if you are root)

The current directory is the folder in which your commands run. It changes when you move around the folders.

That last sign deserves a glance before every command. If the prompt ends with #, you are logged in as root, the administrator. Stay a regular user unless you explicitly need otherwise: a mistake as root asks for no confirmation and can break the system. To run a single command with root rights, the guide Use sudo: run a command as root explains how to do it without switching accounts.

On RHEL, the default prompt looks like [bob@server ~]$: the same information, inside square brackets and without the colon, and only the name of the current directory is shown, not its full path. The prompt can be customised with the PS1 variable, as shown in Customise Bash: .bashrc, prompt, bash-it and fzf.

Check which shell is active

The $SHELL variable (an environment variable: a name to which the shell attaches a value) holds the default shell of your account, the one it starts at login (its login shell). It is not necessarily the one you are using right now: if you type zsh from Bash, $SHELL still says Bash. Two commands show the shell actually running. The first prints the name under which it was started:

Terminal window
echo "$0"

In a login shell, the kind an SSH session or a login on the console opens, the result starts with a dash: -bash. That dash is added by the program that opens the session (sshd, login), and it is how Bash knows it is a login shell. In a graphical terminal window you will usually read bash, without the dash. You will also read bash after bash -l: that command does ask for a login shell, but you are the one starting Bash, so there is no dash.

The second command gives the bare name, whatever the way it was started. It queries the process table (the list of running programs):

Terminal window
ps -p $$ -o comm=

Here $$ is the process number (PID) of the current shell: ps therefore prints the name of the program that carries this number. If the result is bash, zsh or fish, that is the shell you are working in right now.

Type your first commands

A command is a word typed on the keyboard and confirmed with Enter. The shell runs it and displays the result. The options and arguments that can follow it are explained in Anatomy of a Linux command.

  1. Who am I?

    Terminal window
    whoami

    Displays the name of the logged-in user (e.g. bob).

  2. Where am I?

    Terminal window
    pwd

    Displays the full path of the current directory (e.g. /home/bob). This is the path that the prompt shortens to ~ when you are in your home directory.

  3. On which machine?

    Terminal window
    hostname

    Displays the name of the machine.

  4. What date and time is it?

    Terminal window
    date

    Displays the system date and time.

  5. Which distribution?

    Terminal window
    cat /etc/os-release

    cat displays the content of a file. Here, /etc/os-release describes the installed distribution: its name and its version.

  6. Which kernel?

    Terminal window
    uname -r

    Displays the version of the kernel, the core program of Linux, the one that drives the hardware.

On macOS, the built-in Terminal runs zsh, whose prompt ends with % rather than $. The other commands above run there too, except cat /etc/os-release: that file does not exist on macOS.

A trap shows up from the very first command: Linux distinguishes upper case from lower case, in command names as well as in file names. whoami works, Whoami does not, and the message you get says nothing about case: it only says the command cannot be found.

Understand the first errors

When you make a mistake, Bash displays a message. These are the most common errors at the very beginning:

What you typeMessageWhat happened
Whoamicommand not foundNo command with that name: wrong case or typo, or the program is missing
ls /missing-directoryNo such file or directoryThe path does not exist
cat /root/secretPermission deniedYou do not have the rights
cd /etc/passwdNot a directoryIt is a file, not a directory

Read the whole message before typing the command again. It almost always says what is wrong: an incorrect name, a path that does not exist, a missing right. Retyping at random wastes far more time than reading one line. Depending on the language configured on the machine, these messages may appear in another language, such as French, rather than in English: their meaning stays the same.

Copy and paste in the terminal

The terminal does not use the same shortcuts as the rest of the desktop.

ActionShortcut
CopyCtrl + Shift + C
PasteCtrl + Shift + V

One precaution matters when pasting. From Bash 5.1 on, bracketed paste is enabled by default: the shell inserts the pasted text without running it, and nothing is sent before you press Enter. An older shell, or a terminal that does not support this mode, on the other hand runs each line ending with a line break as soon as it is pasted. So always reread what you paste, especially when it comes from a web page: an extra command can hide at the end of the block.

Leave the terminal

Two ways to close your session cleanly:

Terminal window
exit

Or press Ctrl + D on an empty line: this shortcut tells the shell that there is nothing more to read (an end of input, or "end of file"), and the shell closes because it has no command left to wait for. It also works for a command that reads your input, such as cat run without an argument.

Ctrl + D does not always close the shell. If the IGNOREEOF variable is set, Bash requires several consecutive Ctrl + D, 10 if the variable has no numeric value. That is why exit remains the reliable method, whatever the configuration of the machine.

Do not confuse Ctrl + D with Ctrl + C, which interrupts the running program without closing the shell. They are two different gestures, and interrupting a program can leave things half done. The box below, optional on a first pass, explains why Ctrl + D does not act like Ctrl + C.

Put it into practice

Reading the prompt in a guide and reading it in your own session are not the same exercise. The lab opens a disposable shell for you: there you identify your user, your current directory and the machine with whoami, pwd and hostname, and each output is compared with the expected result. In the course on AI-generated applications, this lab is optional.

Key points

  • The terminal is the interface, the shell is the program that interprets your commands.
  • The prompt tells you who you are, on which machine and in which directory.
  • The prompt ends with $ for a regular user and with # for root.
  • whoami, pwd, hostname, date: four commands to find out where you stand.
  • Read the error messages: they almost always explain the problem.
  • Ctrl+D signals the end of input and closes the shell on an empty line; Ctrl+C interrupts the running program.
  • exit closes the session cleanly.

Knowledge check

Check that the essentials of this guide stuck. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer