The Terminal & Prompt

The terminal is the window where you type commands; the prompt is the line waiting for your input.

A terminal (or terminal emulator) is the window that displays the shell. When you open it you see a prompt — a short line ending in a symbol that means "I am ready for a command".

Reading the prompt

A typical prompt looks like this:

alice@server:~$
  • alice — the user you are logged in as.
  • server — the name of the machine (the hostname).
  • ~ — your current folder (~ is a shortcut for your home directory).
  • $ — you are a normal user. A # here would mean you are the all-powerful root user.

You type a command after the $ and press Enter to run it.

Example

Example · bash
# A prompt ending in $ means a normal user:
alice@server:~$ whoami
alice

# A prompt ending in # means the root (admin) user:
root@server:~# whoami
root

When to use it

  • A remote sysadmin opens a terminal over SSH to diagnose a failing web server without a graphical desktop.
  • A developer uses tmux panes in the terminal to edit code, run tests, and tail logs simultaneously.
  • A student uses Tab completion in the terminal to discover command options without memorising every flag.

More examples

Read and understand the prompt

Breaks down each field of the Bash prompt so you can always tell who you are and where you are.

Example · bash
# Format: user@hostname:current_directory$
alice@webserver:/var/log$ whoami
alice
alice@webserver:/var/log$ hostname
webserver

Use command history

Demonstrates the history command and bang-history shortcuts that speed up terminal use.

Example · bash
# Show last 10 commands
history 10

# Re-run the previous command
!!

# Re-run last command starting with 'git'
!git

Customise the PS1 prompt

Changes the PS1 variable to display a timestamp, showing that the prompt is fully configurable.

Example · bash
# Add timestamp to the prompt
export PS1='[\t] \u@\h:\w\$ '
# Result: [14:05:32] alice@server:~$

# Make it permanent
echo "export PS1='[\t] \u@\h:\w\$ '" >> ~/.bashrc

Discussion

  • Be the first to comment on this lesson.