Opening and Using a Terminal

Su Suriya Ravichandran Updated 06 Dec 2026
8 min read ·Lesson 11 of 205

A terminal is the window in which you type commands and read their results. Bash runs inside it, waiting for you to type a line, running that line, and printing the outcome. Before you can write scripts, you need to be comfortable opening a terminal on your system, reading what it shows, and using the keyboard shortcuts that make typing commands fast.

Understanding the Concept

The program you open is called a terminal emulator. The name comes from history: early computers were operated from physical terminals, which were a keyboard and a screen connected to a large machine. A modern terminal emulator imitates one of those devices inside a normal window.

The terminal itself does only two jobs: it shows text and it passes your keystrokes along. It does not understand commands. Behind the window, the terminal starts a shell, and in this tutorial the shell is Bash. Bash reads each line you type, works out what it means, runs it, and sends the output back to be drawn in the window.

You type a line  ->  Terminal window  ->  Bash  ->  Command runs
                                          |
Output appears   <-  Terminal window  <---+

This split explains why one shell can run in many different windows, and why the same window can run different shells.

Opening a Terminal

On Linux

Most Linux desktops provide a terminal application, and the names vary by distribution:

  • Ubuntu and Debian (GNOME): press Ctrl + Alt + T, or search for "Terminal" in the applications menu.
  • Fedora (GNOME): open the Activities overview and search for "Terminal" or "Console".
  • KDE Plasma: search for "Konsole".
  • Xfce: search for "Xfce Terminal".

The shortcut Ctrl + Alt + T works on many desktops, but it is a desktop setting rather than a Bash feature, so it may not exist on yours.

On macOS

Press Command + Space to open Spotlight, type Terminal, and press Return. You can also open Finder, go to Applications, then Utilities, then Terminal. Recent macOS versions start Zsh by default, so type bash to enter a Bash session, as explained in the lesson on using Bash on macOS.

On Windows

Windows does not include Bash in its standard command window. Install the Windows Subsystem for Linux (WSL), then open Windows Terminal from the Start menu and choose your Linux distribution from the drop-down list next to the tab bar. Typing the distribution name, for example Ubuntu, into the Start menu also opens a Bash session directly.

Over a Remote Connection

Servers usually have no desktop, so you reach their shell over SSH:

ssh username@server-address

After you log in, you see a Bash prompt on the remote machine. Everything in this lesson applies there exactly as it does locally.

Reading the Prompt

When Bash is ready for a command, it shows a prompt. A common default looks like this on a Linux system:

student@laptop:~$

Each part carries information:

PartMeaning
studentThe user name you are logged in as
@A separator
laptopThe name of the computer
:A separator
~The current directory, where ~ stands for your home directory
$Marks an ordinary user; Bash is waiting for input

If the prompt ends with # instead of $, you are logged in as the administrator (root). Root can change or delete almost anything, so take extra care with every command in that state.

The exact appearance of the prompt varies between systems because it is configurable. In this tutorial, examples show the prompt as $ at the start of a line you type, and the lines below it are the output. You do not type the $.

$ echo Hello
Hello

Typing and Running a Command

Click inside the terminal window so that it has focus, type a command, and press Enter. Nothing runs until you press Enter, so you can correct mistakes first. When the command finishes, Bash prints a new prompt.

$ pwd
/home/student
$

The command pwd prints the directory you are in. The second $ is the new prompt, which tells you the command is finished and Bash is ready again.

If you press Enter on an empty line, Bash prints a fresh prompt and nothing else happens.

Editing the Line You Are Typing

Bash uses a library called Readline for the input line. Readline provides editing keys that save a great deal of typing. These work in the terminal on every platform:

KeysAction
Left / Right arrowMove the cursor one character
Ctrl + AJump to the start of the line
Ctrl + EJump to the end of the line
Ctrl + UDelete from the cursor back to the start of the line
Ctrl + KDelete from the cursor to the end of the line
Ctrl + WDelete the word before the cursor
Ctrl + LClear the screen

Suppose you typed a long command with a mistake in the first word. Press Ctrl + A to jump to the start and fix it, instead of pressing the left arrow many times.

On macOS, the Terminal application also uses Option + Left and Option + Right to move by word when the "Use Option as Meta key" setting is enabled. Settings like this belong to the terminal, not to Bash.

Using Tab Completion

Press Tab and Bash tries to finish the word you are typing. Suppose your current directory contains a file named quarterly_report_2026.txt:

$ cat quar<Tab>

Bash completes the name:

$ cat quarterly_report_2026.txt

If several names start with the same letters, Bash completes as much as it can. Pressing Tab a second time lists the possible matches:

$ cat q<Tab><Tab>
quarterly_report_2026.txt  quick_notes.txt

Type another letter or two to make the choice unique, then press Tab again. Tab completion also works on command names, so typing his and pressing Tab completes history. Because it uses the real file names, it also prevents typing errors.

Reusing Earlier Commands with History

Bash remembers the commands you ran. This lets you repeat or adjust a command without typing it again.

  • Press the Up arrow to show the previous command, and again to go further back. Press the Down arrow to move forward.
  • Press Ctrl + R and start typing part of an old command. Bash searches backwards through the history and shows the most recent match. Press Enter to run it, or press the right arrow key to edit it first.
  • Run history to print the numbered list of past commands.
$ history | tail -3
  101  cd projects
  102  ls
  103  history | tail -3

The exact numbers and commands will be different on your machine. The | symbol sends the output of history into tail -3, which keeps only the last three lines. Pipes are explained in a later lesson.

You can run a command from the list by its number:

$ !101
cd projects

Bash prints the command it expanded and then runs it. The shortcut !! repeats the previous command, which is handy after you forget a leading administrator command:

$ sudo !!

Stopping and Ending Things

Some keys do not edit text. They control the running program or the shell itself.

KeysAction
Ctrl + CInterrupt the running command and return to the prompt
Ctrl + DSend "end of input"; on an empty prompt, this closes the shell
Ctrl + ZPause the running command and send it to the background

Ctrl + C is the key to remember. If a command seems stuck or prints too much, press it:

$ sleep 60
^C
$

The sleep command waits for 60 seconds. Pressing Ctrl + C shows ^C and cancels it immediately. The Ctrl + Z key is described in the lessons about job control.

To close the shell, type exit and press Enter, or press Ctrl + D on an empty line. When the shell ends, a terminal window usually closes with it.

Copying and Pasting

The usual Ctrl + C shortcut cannot copy in a terminal because it already means "interrupt". Terminals therefore use different shortcuts:

SystemCopyPaste
Most Linux terminalsCtrl + Shift + CCtrl + Shift + V
macOS TerminalCommand + CCommand + V
Windows TerminalCtrl + Shift + C or Ctrl + C with a selectionCtrl + Shift + V or Ctrl + V

Many Linux terminals also paste the most recently selected text when you press the middle mouse button.

Be careful when you paste commands from a web page. A pasted line may run at once if it ends with a newline, so read the command first, especially if it begins with sudo.

Windows, Tabs, and Scrolling

A terminal can hold several shell sessions at the same time. Each session has its own current directory, variables, and history position:

  • Open a new tab with Ctrl + Shift + T on most Linux terminals, or Command + T on macOS.
  • Open a new window with Ctrl + Shift + N on most Linux terminals, or Command + N on macOS.
  • Scroll back through earlier output with the mouse wheel or Shift + Page Up.

Having separate tabs is useful when you need one session to run a long task while another is free for new commands.

A Complete First Session

The following sample session uses only the keys and commands from this lesson. The outputs are examples, because user names and directories are different on every machine.

$ echo "Terminal is working"
Terminal is working
$ pwd
/home/student
$ clear
$ history | tail -2
  15  clear
  16  history | tail -2
$ exit

The steps show how the pieces fit together:

  1. echo prints text, which confirms that Bash is reading your input.
  2. pwd shows where the session currently is.
  3. clear wipes the visible screen, but earlier output is still in the scroll buffer.
  4. history | tail -2 shows the two most recent entries from the history list. The list includes the history command itself, because Bash records a line before it runs.
  5. exit ends the shell and closes the session.

0 Comments

Reviewed before they appear

No comments yet.

Bash
Introduction to Bash What Is a Shell? What Is Bash (Bourne Again Shell)? Bash vs. Shell vs. Terminal Bash vs. sh, Zsh, and Fish Where Bash Is Used: Linux, DevOps, and Automation Installing Bash on Linux Using Bash on macOS Using Bash on Windows with WSL Checking Your Bash Version Opening and Using a Terminal Running Your First Bash Command Understanding Command Syntax and Arguments Bash Built-in Commands vs. External Commands Working with pwd, ls, and cd Creating Files and Directories with touch and mkdir Copying, Moving, and Renaming Files Removing Files and Directories Safely Viewing Files with cat, less, head, and tail Searching for Files with find Searching Text with grep Understanding File Paths and Wildcards Using man Pages and Command Help Bash Script Structure Creating Your First Bash Script Understanding the Shebang (#!/usr/bin/env bash) Making a Script Executable with chmod Running a Bash Script in Different Ways Writing Comments in Bash Using echo and printf Reading User Input with read Displaying Helpful Messages in Scripts Using Semicolons and Newlines Bash Variables: Declaration and Usage Rules for Naming Bash Variables Environment Variables Local Variables vs. Environment Variables Exporting Variables with export Common Environment Variables: HOME, PATH, USER, and PWD Read-Only Variables with readonly Removing Variables with unset Command-Line Arguments: $0, $1, and More Special Parameters: $#, $?, $$, $!, $@, and $* Positional Parameters and shift Default Values with Parameter Expansion Single Quotes vs. Double Quotes Escaping Special Characters Command Substitution with $(...) Arithmetic Expansion with $((...)) Brace Expansion Tilde Expansion and Home Directories Filename Expansion and Globbing Understanding Word Splitting Parameter Expansion Basics Why Quoting Variables Matters Standard Input, Standard Output, and Standard Error Redirecting Output with > and >> Redirecting Input with < Redirecting Errors with 2> Combining Standard Output and Standard Error Using Pipes (|) to Connect Commands Using tee to Save and Display Output Here Documents with << Here Strings with <<< Command Lists with ;, &&, and || Conditional Statements with if, then, and fi Using elif and else Testing Conditions with test and [ ] Using [[ ]] for Bash Conditionals Comparing Strings in Bash Checking Whether Files Exist Checking File Types and Permissions Integer Comparisons in Bash Logical Operators: &&, ||, and ! Using case Statements Pattern Matching in case Common Conditional Statement Mistakes for Loops in Bash C-Style for Loops while Loops until Loops Looping Through Files and Directories Looping Through Command Output Safely break and continue Nested Loops select Loops for Simple Menus Avoiding Infinite Loops Defining and Calling Bash Functions Passing Arguments to Functions Returning Status Codes from Functions Understanding return vs. echo in Functions Local Variables in Functions Function Scope and Variable Visibility Organizing Scripts into Functions Sourcing Other Bash Files with source Reusable Bash Utility Functions Indexed Arrays in Bash Creating and Accessing Array Elements Adding and Removing Array Elements Looping Through Arrays Array Length and Indices Associative Arrays in Bash Iterating Over Associative Arrays Passing Arrays to Functions Common Array Pitfalls Processing Text with grep, sed, and awk Using cut, sort, uniq, and wc Finding and Replacing Text with sed Extracting Columns with awk Parsing CSV-Like Text from the Command Line Working with Filenames That Contain Spaces Safe File Handling with find -print0 and xargs -0 Temporary Files with mktemp Reading Files Line by Line Appending Logs to a File Understanding Exit Codes Checking Command Success with $? Using exit to End a Script Fail-Fast Scripts with set -e: Benefits and Caveats Using set -u and set -o pipefail Combining Strict Mode Options Safely Handling Errors with if Statements Traps with trap Cleaning Up Temporary Files on Exit Writing Useful Error Messages Debugging Scripts with bash -x Parsing Script Arguments Validating Required Arguments Handling Optional Arguments Parsing Options with getopts Building Help Messages with --help Setting Defaults for Optional Parameters Handling Unknown Options and Invalid Input Creating Interactive Menus in Bash Foreground and Background Processes Running Commands in the Background with & Managing Jobs with jobs, fg, and bg Waiting for Processes with wait Capturing Process IDs with $! and $$ Sending Signals with kill Handling Interrupts and Termination Signals Running Commands with timeout Basic Process Monitoring from Bash Aliases and Shell Functions: When to Use Each Customizing the Bash Prompt (PS1) Bash Startup Files: .bashrc, .bash_profile, and Profile Interactive vs. Non-Interactive Bash Shell Options with set shopt: Enabling Bash-Specific Options Directory Stack with pushd, popd, and dirs Process Substitution with <(...) and >(...) Advanced Parameter Expansion Pattern Matching and Extended Globbing Bash Script Security Fundamentals Avoiding Command Injection in Shell Scripts Quoting User Input Safely Why eval Is Risky and Safer Alternatives Handling Secrets and Credentials in Scripts Using Least Privilege in Automation Scripts Safe Use of rm and Destructive Commands Validating Paths and User-Supplied Filenames ShellCheck: Static Analysis for Bash Scripts Writing Readable and Maintainable Bash Automating Backups with Bash Creating Log Rotation and Cleanup Scripts Checking Disk Usage and Free Space Monitoring CPU, Memory, and System Load Checking Website Availability with curl Automating Updates on Ubuntu and Debian Scheduling Bash Scripts with cron Using Lock Files to Prevent Duplicate Runs Building a Simple Health-Check Script Sending Notifications from Bash Scripts Using Bash in Git Workflows Bash Scripts for Docker Automation Automating Docker Container Health Checks Using Bash in CI/CD Pipelines Environment Configuration for Deployment Scripts Automating SSH Tasks with Bash Deploying a Web Application with a Bash Script Using Bash to Process Application Logs Building Repeatable Development Setup Scripts Bash Debugging Techniques Using set -x and PS4 for Debug Traces Testing Bash Scripts with Bats Mocking Commands During Script Tests Testing Error Paths and Exit Codes Writing Portable Shell Scripts Bash-Specific Syntax vs. POSIX Shell Syntax Using ShellCheck in a Development Workflow Performance Tips for Bash Scripts Build an Interactive Calculator Build a File and Directory Organizer Build a Timestamped Backup Script Build a Log File Analyzer Build a Bulk File Renaming Tool Build a System Resource Monitoring Script Build a Website Uptime Checker Build a User Account Audit Report Build a Database Backup Automation Script Build a Docker Cleanup Helper Build a Server Health-Check and Alert Script Build a Deployment Automation Script Build a Menu-Driven Linux Administration Toolkit Build a Safe Automated Backup and Restore Workflow
Ask about this post
AI Ask about this post

Ask questions about Opening and Using a Terminal and get answers drawn from it.

Signed-in readers only.