datarekha

What is the shell?

Understand what the terminal, the shell, and bash/zsh actually are — and why the command line is worth learning.

5 min read Beginner Command Line Lesson 1 of 14

What you'll learn

  • The difference between a terminal, a shell, and the kernel
  • How to read a shell command: command, flags, and arguments
  • Where to find help when you're stuck (man, --help, tldr)

Whether you arrived here straight from the Git course or you are starting fresh, you have almost certainly typed into this window before — git, python, an install command someone pasted you — without ever naming what was actually reading those commands. That nameless thing is a shell, running inside a terminal, asking the operating system to act. Pulling those three apart is the foundation of everything that follows.

Three things people often confuse

When you “use the command line,” you are actually working with three separate things stacked on top of one another.

The terminal is just the window — the app you open. On macOS it is called Terminal (or iTerm2, Warp, etc.). On Windows it is Windows Terminal. The terminal does nothing clever; it is a box that shows text and passes your keystrokes somewhere else.

The shell is the program that lives inside that box. The shell reads what you type, figures out what you mean, and asks the operating system to do it. Common shells:

ShellWhere you’ll see it
bashLinux servers, older macOS, CI systems
zshmacOS default since Catalina (2019)
shMinimal POSIX shell, available everywhere
fishBeginner-friendly, not POSIX-compatible

The kernel is the core of the operating system. The shell talks to it (and to other programs) on your behalf. You never interact with the kernel directly.

Terminal(the window)iTerm2, TerminalWindows TerminalShell(the program)bash, zsh, shKernel / OS(files, processes)Linux, macOSWindowsoutput
You type in the terminal; the shell reads it and asks the kernel; output flows back.

The read-eval-print loop

A shell is a loop. Every time you press Enter, the shell:

  1. Reads the line you typed
  2. Evaluates it — parses the command, sets up any pipes or redirections, then runs the program
  3. Prints the output back to the terminal
  4. Loops back and shows a new prompt

This is called a REPL (read-eval-print loop). Python’s interactive mode works the same way.

Anatomy of a command

A command has up to three parts, separated by spaces:

command   options/flags   arguments
ls        -l              /tmp
  • command — the program to run (ls lists files, cp copies, rm deletes)
  • options / flags — modify the behavior; usually start with - (short) or -- (long), e.g. -l or --long
  • arguments — what the command acts on, e.g. a file path or a search term

Try it live:

ls -l /tmp
total 0
drwx------  3 alice  wheel   96 Jun  5 09:14 com.apple.launchd.xyz
-rw-r--r--  1 alice  wheel    0 Jun  5 09:00 tempfile.txt

You can stack short flags: ls -la is the same as ls -l -a (long listing plus hidden files).

The prompt

Before every line, the shell prints a prompt — a signal that it is waiting for you. A typical prompt looks like:

alice@macbook ~ $
  • alice — your username
  • macbook — the computer name
  • ~ — your current directory (~ is shorthand for your home folder)
  • $ — you are a normal user; the shell uses # instead when you are root (the administrator)

The prompt is purely informational. You do not type it — only what comes after it.

Why bother with the CLI?

The graphical interface is great for exploration. The command line is better for:

  • Speed — one command replaces dozens of clicks
  • Scripts — chain commands together and save them as a file you can replay
  • Remote servers — SSH gives you a shell on a machine halfway around the world; there is often no graphical interface available
  • Reproducibility — paste a command into a README and anyone can repeat exactly what you did

Getting help

You will forget flags. Everyone does. Three tools to know:

man ls

Opens the full manual page for ls. Press q to quit.

ls --help

Prints a shorter summary. Works for most programs.

tldr ls

Shows practical examples only. Install with brew install tldr on macOS or npm install -g tldr. Highly recommended for beginners.

In one breath

Three things stack up when you “use the command line”: the terminal is just the window that shows text and passes keystrokes along; the shell (bash, zsh, sh) is the program inside it that reads each line, runs it, prints the result, and loops — a read-eval-print loop; and the kernel is the OS core the shell asks to do the actual work. A command reads left to right as command [flags] [arguments]ls -l /tmp runs ls, modified by -l, acting on /tmp — and everything is case- and space-sensitive with no “are you sure?” safety net. The prompt’s $ (normal user) or # (root) just signals the shell is waiting. When you forget a flag, reach for man, --help, or the example-first tldr.

Practice

Before the quiz, dissect a command you will meet constantly: cp -r ~/notes /tmp/backup. Name each of its four pieces — which is the command, which the flag, which the arguments — say what -r most likely does and what ~ expands to, and explain why a stray space turning the last argument into /tmp/ backup would break it.

Quick check

0/3
Q1You open the Terminal app on macOS. What is the *shell* in that scenario?
Q2What does the $ symbol at the end of a shell prompt indicate?
Q3A colleague sends you the command `grep -r 'TODO' ./src`. You have never used grep before. Which approach gives you practical usage examples fastest?

A question to carry forward

Look again at that prompt: alice@macbook ~ $. The little ~ is quietly telling you something important — the shell is never floating in a void; it is always standing somewhere in the filesystem, and right now that somewhere is your home folder. Every command runs from that spot: ls lists what is here, a relative path like ./src is relative to here. So before you can do anything useful, you need three things at your fingertips — where am I, what is around me, and how do I move. That is navigating the filesystem, and it is the next lesson.

Sign in to track your progress

Completed lessons, your XP, level, and streak save to your account — it's free and takes a few seconds.

Related lessons

Skip to content