Skip to content
Ameen Abozaid
PublishedBEG-006-L01

Terminal, shell, and prompt

  • Lesson 1 of 8
  • 12 min read
  • Beginner
On This Lesson 11 topics

Lesson Overview

So far you have used a computer by clicking: folders, windows, buttons. In Module 5 you already typed a few commands, such as java -version, and the computer answered. This module turns that small habit into a real skill: working with the computer by writing short instructions and reading the replies.

The picture we use is giving written orders to a very literal assistant. The assistant does exactly what you write, never guesses, and never asks "did you really mean that?" unless you ask it to. That makes it fast and powerful, and it is also why you will learn to read before you press Enter.

This first lesson answers three questions. What is the window you type into? What is the program that understands your words? What is the line of text that waits for you? Then it shows the basic rhythm of every command: type, press Enter, read the result.

The lesson needs only Module 5. Terminal programs and menus differ between Windows, macOS, and Linux, so the steps below name the usual routes and tell you to check your system's own help if yours differs.

Learning Objectives

By the end of this lesson you will be able to:

  • Explain the difference between a terminal and a shell.
  • Name two shells (Bash and PowerShell) and say which one you will use on your computer.
  • Read a prompt and say what information it gives you.
  • Run a command by typing it, pressing Enter, and reading the output.
  • Split a command into its command name, options, and arguments.
  • Cancel a command, clear the screen, recall an earlier command, and ask for help.
  • Give two reasons developers use the command line.

Written Explanation

The terminal is the window

A terminal (also called a terminal emulator or console window) is the program that gives you a place to type and a place to read text. It shows characters on the screen and sends your keystrokes onward. It does not understand your commands.

Examples you may have: Windows Terminal, the macOS Terminal app, or a terminal window in IntelliJ IDEA or VS Code (both IDEs from Module 5 have one built in). The names and look differ; the idea is the same.

The shell is the program that reads your commands

A shell is the program that runs inside the terminal. It reads each line you type, works out what you mean, runs the program you asked for, and prints the result back.

Think of the terminal as the telephone and the shell as the assistant who answers it. You can swap the telephone without changing the assistant, and the same telephone can connect you to a different assistant.

Two shells matter in this module:

ShellTypical homeNotes
BashLinux; also available on macOS and, through tools such as Git Bash or WSL, on WindowsThe classic Unix shell. Recent macOS versions use a close relative called zsh by default, and the basic commands in this module work the same there.
PowerShellWindows; also installable on macOS and LinuxMicrosoft's shell. Its commands are named like Get-ChildItem, and many have short aliases.

Which should you use? Use PowerShell if you are on Windows and Bash (or zsh) if you are on macOS or Linux. Every lesson shows both. Lesson 7 puts the two side by side so you can read either one.

The prompt waits for you

The prompt is the short piece of text the shell prints when it is ready for a command. Its exact shape depends on your shell and settings:

text
ana@laptop:~/projects$            (Bash on Linux, typical)
ana@laptop ~ %                    (zsh on macOS, typical)
PS C:\Users\Ana\projects>         (PowerShell on Windows, typical)

Prompts usually tell you who you are, which computer you are on, and, most usefully, where you are: your current folder. The ~ in the first two lines is shorthand for your home folder, which Lesson 2 explains. The $, %, and > at the end are only markers meaning "type here".

When a lesson shows a command, it often writes the prompt marker first, like $ echo hello. Do not type the marker. Type only what follows it.

Your prompt can be changed, so yours may look different from these examples. That is fine. The point is to learn to read yours.

Run a command: type, Enter, read

Every use of the command line has the same rhythm:

  1. Type a command after the prompt.
  2. Press Enter. Nothing runs until you do.
  3. Read the output the shell prints.
  4. Wait for the prompt to come back. That means the command has finished.

Try this in your own terminal. echo prints whatever you give it, and it works in both shells:

text
$ echo hello
hello

Now two commands that ask the computer a question. whoami and hostname exist in both Bash and PowerShell on Windows, macOS, and Linux (on Windows they are standard programs):

text
$ whoami
ana
$ hostname
laptop

Your output will show your own names, not ana and laptop.

The anatomy of a command

A command line is split into words separated by spaces:

text
ls -l projects
  • ls is the command name: what to do.
  • -l is an option (also called a flag or switch): it changes how the command behaves. In Bash, short options usually start with one dash, and long ones with two, as in --help.
  • projects is an argument: what to do it to.

Spaces are the dividers, which is why a name containing a space needs quotation marks. Lesson 2 returns to that. Capital letters can matter too: on Linux and macOS, file names and commands are usually case-sensitive, so LS is not ls. Windows is generally more forgiving about the case of file names.

PowerShell options look different. They are written with a dash and a longer name, for example Get-ChildItem -Force. You will see the difference in Lesson 7.

Five habits that save time

These keys work in most terminals, though the details can vary. Check your terminal's help if one does not.

  • Up arrow brings back the previous command so you can edit and run it again. Press it repeatedly to go further back.
  • Tab completes a name for you. Type the first letters of a file or folder, press Tab, and the shell fills in the rest if it is unambiguous. This saves typing and prevents spelling mistakes.
  • Ctrl+C cancels the command that is running. Use it when something seems stuck.
  • clear wipes the screen so you can start fresh. It does not undo anything you did. (It works in both shells.)
  • history lists the commands you typed earlier. It exists in both shells, and the lab at the end of this module asks you to save such a history.

Asking for help

Bash users can usually ask a program for help with --help after its name, for example ls --help, or open a manual page with man ls. Options differ a little between Linux and macOS, so read your own system's help. PowerShell uses Get-Help, for example Get-Help Get-ChildItem; it may offer to download updated help files, which you can decline.

Why bother with the command line?

  • It is fast. One line can do what takes many clicks, and Tab and Up Arrow shorten it further.
  • It is repeatable. A command can be written down, shared, and run again with the same result. A sequence of clicks cannot.
  • Servers often have no screen. A backend program usually runs on another computer, which you reach by typing commands. There is often no desktop to click.

The command line also has a cost: it is unforgiving. It will not ask for confirmation for most commands, and errors can be terse. The habit you build in this module is to read before you press Enter.

Examples

Example 1: A first conversation (simple)

Open a terminal and run these three commands one at a time, pressing Enter after each. Replace the sample answers with your own:

text
$ echo Hello, terminal
Hello, terminal
$ whoami
ana
$ clear

You gave a command, read a reply, and cleared the screen. After clear, nothing has been undone. The computer is just as it was.

Example 2: Splitting a command into parts (practical)

Take this line, which lists files in a detailed format (Bash and zsh; PowerShell has its own form):

text
$ ls -l Documents
WordRole
lsCommand name: list the contents of a folder
-lOption: use a detailed ("long") format
DocumentsArgument: the folder to list

Now the same job in PowerShell: Get-ChildItem Documents. Here Get-ChildItem is the command name and Documents is the argument. The idea is the same in both shells: name, options, arguments.

Example 3: Recovering from a command that does not stop (realistic)

You type ping followed by a computer name, and the output keeps scrolling with no end (on Linux and macOS, ping keeps going until you stop it; Windows' version stops after a few tries). A beginner may think the terminal is frozen.

The prompt has not come back, which means the command has not finished. Press Ctrl+C, and the shell stops the command and prints a new prompt. Then press the Up arrow to recall the earlier line if you want to change and rerun it.

This is the shell's rhythm in action: no prompt means "still busy", and a new prompt means "ready for the next order".

Backend Insight

Backend software runs on servers, and servers are mostly managed from a terminal. You will connect to a remote machine, start and stop your service, read its log files, and set its configuration, all by typing. There is often no desktop environment installed at all.

For that reason, the command line is the one interface that is the same on your laptop and on a server: if you can do a job by typing, you can write it down in a script and run it on any machine. Tools you will meet later in the course, such as Git, Maven or Gradle, Docker, and database clients, are mainly used from the command line. This module gives you the base for all of them. Module 5's java -version was your first taste.

Common Mistakes

Mistake 1: Calling the terminal and the shell the same thing

  • Incorrect: "I am running a terminal called PowerShell."
  • Correct: "I opened a terminal window, and the shell inside it is PowerShell."

The difference matters when something goes wrong. If the window looks odd, the terminal is the cause. If a command is not recognised, the shell is.

Mistake 2: Typing the prompt marker

If a lesson shows $ echo hello and you type $ echo hello, the shell will complain that it does not know $. The marker is part of the display, not the command.

Mistake 3: Mixing Bash and PowerShell commands

ls -l works in Bash, while Get-ChildItem -Force is PowerShell. Typing the wrong one gives an error such as "command not found" or "is not recognized". Check the prompt first: PS at the start of the line means PowerShell.

Exercises

Try each exercise yourself before opening the solutions.

Level A: Foundation

A1. In one sentence each, say what a terminal is and what a shell is.

Show solution A1

A1. A terminal is the window that shows text and sends your keystrokes onward. A shell is the program inside it that reads your commands, runs them, and prints the results.

A2. Look at this prompt: PS C:\Users\Ana\work>. Which shell is it, and where is the user?

Show solution A2

A2. It is PowerShell, because of the PS at the start. The user is in the folder C:\Users\Ana\work.

A3. In ls -l notes, name the command, the option, and the argument.

Show solution A3

A3. The command is ls, the option is -l, and the argument is notes.

Level B: Application

B1. Open a terminal on your own computer. Write down the full prompt as it appears. Say which shell it shows and what your current folder is.

Show solution B1

B1. Answers depend on your computer. Example: PS C:\Users\Ana> means PowerShell and a current folder of C:\Users\Ana. On Linux, ana@laptop:~$ means a Bash-style shell, with ~ standing for the home folder. If you cannot tell the shell from the prompt, read the window title or ask the shell directly in the next lesson.

B2. Run echo, whoami, and hostname. Copy each command and its answer into a note. Which of them took an argument?

Show solution B2

B2. echo needed an argument (the text it prints). whoami and hostname ran with no argument. Your own output will show your own user and computer names.

B3. Run echo one, then echo two, then echo three. Use only the Up arrow, not retyping, to run echo two a second time.

Show solution B3

B3. Run the three echo commands in order, then press Up arrow twice (once gives echo three, twice gives echo two), then press Enter. If your terminal behaves differently, check its help.

Level C: Challenge

C1. A friend says: "I closed my terminal, so I deleted the shell." Correct them, using the terminal and shell definitions.

Show solution C1

C1. Closing the window closes the terminal and ends that shell session, but the shell program is still installed on the computer. Nothing was deleted. You can open a new terminal and start a new shell session.

C2. In your own words, list three differences between giving the computer an order by clicking and by typing a command. Give one advantage and one risk of typing.

Show solution C2

C2. Possible answer: typing is repeatable and can be written down, it is often faster, and it works on servers without a screen. Clicking shows you what is there and warns you more often. The risk of typing is that the shell does what you write, immediately, with little warning, so a typing mistake can change or delete the wrong thing.

Mini Challenge

Create a short "terminal card" for your own computer. In a plain text file or on paper, write:

  1. The name of the terminal you use and how you opened it.
  2. The shell it runs (Bash, zsh, or PowerShell), and how you know.
  3. Your prompt, copied exactly, with an arrow pointing to the part that shows your current folder.
  4. Three keys you will use most, from the five habits above, with a one-line reason for each.
  5. One command you ran, split into command name, options, and arguments.

Check your work: you named the shell separately from the terminal, and you did not copy the prompt marker into a command.

Summary & Next Lesson

Key takeaways

  • The terminal is the window. The shell is the program inside it that reads and runs your commands. Bash and PowerShell are two shells.
  • The prompt shows that the shell is ready, and usually shows your current folder.
  • The rhythm is: type, press Enter, read the output, wait for the prompt.
  • A command line is a command name, options, and arguments, separated by spaces.
  • Up arrow, Tab, Ctrl+C, clear, and history make the terminal faster and safer.
  • The command line is fast, repeatable, and the normal way to work on servers. It is also unforgiving, so read before you press Enter.

Next lesson

You now know what you are typing into. The next lesson, "Paths: absolute, relative, home, . and ..", teaches how to say where things are, so you can move through folders and point commands at the right files.

Self-check

  1. What is the difference between a terminal and a shell?
  2. Name two shells.
  3. What does the prompt tell you, and what does a missing prompt mean?
  4. In Get-ChildItem -Force Documents, which part is the argument?
  5. Give one reason servers are managed from a terminal.
Show answers
  1. The terminal is the window for typing and reading text. The shell is the program inside it that interprets and runs the commands.
  2. Bash and PowerShell (also zsh and Command Prompt).
  3. It shows the shell is ready, and often your current folder. No prompt means the command is still running.
  4. Documents.
  5. Servers often have no screen or desktop, and typed commands can be written down and repeated.

References

  • Microsoft Learn, about_Environment_Variables. Checked for PowerShell's own naming style and for its being available on Windows, macOS, and Linux. The terminal-versus-shell distinction, the prompt shapes, and the keyboard habits are common teaching knowledge that I did not check against a single official page, and key behavior varies by terminal.
  • Microsoft Learn, about_Pipelines. Supports the Verb-Noun command style such as Get-ChildItem and the statement that PowerShell runs on all three systems' native commands too.
  • Not verified on an official page: macOS's current default shell being zsh, Get-Help offering to download help files, and the exact behavior of ping on each system. The text hedges these.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.