The Terminal#

Concepts#

Terminal, Shell, TTY — What Is What?#

These three terms are related but distinct:

Terminal (or terminal emulator) — The window where you type commands. On a graphical desktop, it is an application like GNOME Terminal, Konsole, or xterm. It draws the window, handles fonts and colors, and sends your keystrokes to the shell.

Shell — The program that interprets your commands. When you type ls and press Enter, the shell reads that input, finds the ls program, runs it, and displays the output. The default shell on both Ubuntu and Debian is Bash (Bourne Again Shell). Other shells include zsh, fish, and dash.

TTY — Originally stood for “teletypewriter,” a physical terminal from the pre-screen era. On modern Linux, TTY refers to the virtual consoles available outside the graphical environment. You can switch to them with Ctrl + Alt + F1 through Ctrl + Alt + F6. The graphical desktop typically runs on Ctrl + Alt + F2 (Ubuntu) or Ctrl + Alt + F7 (Debian). TTYs are useful when the graphical desktop crashes or is not installed.

The relationship:

You ──→ Terminal (window) ──→ Shell (Bash) ──→ Operating System
         draws the UI          interprets         executes
                               commands           programs

Anatomy of the Prompt#

When you open a terminal, you see something like this:

user@hostname:~$

Each part means:

Part Meaning
user Your username
@ Separator
hostname The name of your computer
: Separator
~ Your current directory (~ is shorthand for your home directory)
$ You are a normal user. If you see # instead, you are running as root.

Example:

kmiguel@ubuntu-lab:~$        # user kmiguel, machine ubuntu-lab, in home directory
kmiguel@ubuntu-lab:/etc$     # same user, now in the /etc directory
root@ubuntu-lab:/etc#        # running as root (note the # prompt)

Running Commands#

The basic pattern is:

command [options] [arguments]
  • command — The program to run (e.g., ls, pwd, echo)
  • options — Modify the command’s behavior. Usually start with - (short) or -- (long).
    • -l is a short option
    • --long is a long option
    • Short options can often be combined: -l -a is the same as -la
  • arguments — What the command operates on (e.g., a filename, directory, or text)

Examples:

ls                    # list files in the current directory (no options, no arguments)
ls -l                 # list files in long format (one option)
ls -la /etc           # list all files in long format in /etc (two options, one argument)
echo "Hello"          # print "Hello" (one argument)

Getting Help#

Almost every command has built-in documentation:

# The manual page (most comprehensive)
man ls

# Quick help (shorter)
ls --help

# One-line description
whatis ls

# Search for commands related to a keyword
apropos "copy files"

Reading man pages:

  • Press Space to go down a page, b to go back
  • Press / then type a word to search
  • Press n to go to the next match
  • Press q to quit

Man pages are organized in sections:

  1. User commands (what you use day-to-day)
  2. System calls (for programmers)
  3. Library functions (for programmers)
  4. Device files
  5. File formats (like /etc/passwd)
  6. Games
  7. Miscellaneous
  8. System administration commands (require root)

Command History#

Bash remembers every command you type:

  • Up/Down arrows — scroll through previous commands
  • history — show all remembered commands (with numbers)
  • !! — repeat the last command
  • !42 — repeat command number 42 from history
  • Ctrl + R — reverse search: start typing to search through history. Press Ctrl + R again for older matches. Press Enter to execute, or Esc to edit first.

History is saved to ~/.bash_history when you close the terminal.

Tab Completion#

Press Tab to auto-complete commands, filenames, and paths:

  • Type ls /e then press Tab → completes to ls /etc/
  • Type apt ins then press Tab → completes to apt install
  • If there are multiple possibilities (looks like your input did nothing), press Tab twice to see all options

Tab completion saves typing and prevents typos. Use it constantly. Though you should keep in mind the difference between absolute (/etc/) and relative (./etc) paths.

Clearing and Canceling#

Action Key
Clear the screen Ctrl + L (or type clear)
Cancel the current command Ctrl + C
Close the terminal / exit the shell Ctrl + D (or type exit)
Suspend a running program Ctrl + Z (sends it to background)

Lab#

Exercise 1: Identify Your Shell#

Open a terminal and run:

echo $SHELL

Expected output (for a bash shell):

/bin/bash

This is the path to your default shell. Now check the version:

bash --version

Exercise 2: Read Your Prompt#

Look at your prompt. Identify:

  1. Your username
  2. Your hostname
  3. Your current directory
  4. Whether you are root or a normal user ($ or #)

Now change directory and see the prompt update:

cd /tmp
# Your prompt now shows /tmp instead of ~
cd ~
# Back to ~ (home)

Exercise 3: Use Command Options#

# List files (basic)
ls

# List files in long format
ls -l

# List all files (including hidden) in long format
ls -la

# List with human-readable file sizes
ls -lh

# Combine it all
ls -lah

Look at the output of ls -lah. You will learn what each column means in Module 02 (Filesystem). For now, notice how options change the output.

Exercise 4: Get Help#

If you were a normal human being, this would be around the time you realize you are now two hours deep in reading this course and to seek professional help.

For the rest of us here is how to actually read the documentation for once in our life:

# Open the manual for the ls command
man ls
# Use Space to scroll, q to quit

# Quick help
ls --help

# What is ls?
whatis ls

# Find commands related to "directory"
apropos directory

Exercise 5: Command History and Tab Completion#

# Run a few commands
echo "first command"
echo "second command"
ls /etc

# Now press Up Arrow three times — you should cycle back through these commands

# Show your full history
history

# Repeat the last command
!!

# Search history: press Ctrl+R, type "etc", see the ls /etc command appear
# Press Enter to run it, or Esc to edit it first

Now practice tab completion:

# Type this and press Tab:
cat /etc/hos
# It should complete to: cat /etc/hosts  (if unique)
# or show options like hosts, host.conf

# Type this and press Tab twice:
ls /etc/a
# Shows all entries in /etc starting with 'a'

Exercise 6: Clearing and Canceling#

# Fill the screen with output
ls -la /etc

# Clear it
# Press Ctrl+L

# Start a command that runs forever
cat
# (cat with no arguments waits for input forever)
# Press Ctrl+C to cancel it

# Try Ctrl+D to exit the shell
# (This closes your terminal — reopen it to continue)

Review#

1. What is the difference between a terminal and a shell?

The terminal is the window application that handles display (text, colors, fonts) and sends keystrokes to the shell. The shell is the program that interprets and executes your commands. The terminal is the interface; the shell is the interpreter.

2. What is the default shell on Ubuntu and Debian?

Bash (Bourne Again Shell), located at /bin/bash.

3. In the prompt `user@hostname:/etc$`, what does each part mean?

user = your username, @ = separator, hostname = computer name, /etc = current directory, $ = normal user (not root).

4. How do you search through your command history interactively?

Press Ctrl + R and start typing. It searches backward through your history for a match. Press Ctrl + R again to find older matches. Press Enter to execute or Esc to edit the command first.

5. What does pressing Tab do in the terminal?

It auto-completes the current command, filename, or path. If there are multiple possibilities, pressing Tab twice shows all options.

6. How do you cancel a running command?

Press Ctrl + C. This sends an interrupt signal to the running program.

7. What is the difference between `Ctrl + C` and `Ctrl + Z`?

Ctrl + C cancels (terminates) the running program. Ctrl + Z suspends it and sends it to the background — the program is still alive but paused. You will learn more about this in Module 07 (Processes).


Previous: The Desktop Environment | Next: Navigating the Filesystem