Opening and Using a Terminal
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:
| Part | Meaning |
|---|---|
student | The user name you are logged in as |
@ | A separator |
laptop | The 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:
| Keys | Action |
|---|---|
Left / Right arrow | Move the cursor one character |
Ctrl + A | Jump to the start of the line |
Ctrl + E | Jump to the end of the line |
Ctrl + U | Delete from the cursor back to the start of the line |
Ctrl + K | Delete from the cursor to the end of the line |
Ctrl + W | Delete the word before the cursor |
Ctrl + L | Clear 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 + Rand start typing part of an old command. Bash searches backwards through the history and shows the most recent match. PressEnterto run it, or press the right arrow key to edit it first. - Run
historyto 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.
| Keys | Action |
|---|---|
Ctrl + C | Interrupt the running command and return to the prompt |
Ctrl + D | Send "end of input"; on an empty prompt, this closes the shell |
Ctrl + Z | Pause 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:
| System | Copy | Paste |
|---|---|---|
| Most Linux terminals | Ctrl + Shift + C | Ctrl + Shift + V |
| macOS Terminal | Command + C | Command + V |
| Windows Terminal | Ctrl + Shift + C or Ctrl + C with a selection | Ctrl + 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 + Ton most Linux terminals, orCommand + Ton macOS. - Open a new window with
Ctrl + Shift + Non most Linux terminals, orCommand + Non 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:
echoprints text, which confirms that Bash is reading your input.pwdshows where the session currently is.clearwipes the visible screen, but earlier output is still in the scroll buffer.history | tail -2shows the two most recent entries from the history list. The list includes thehistorycommand itself, because Bash records a line before it runs.exitends the shell and closes the session.