1 The shell and the terminal#

Introduction to the Bash Shell
Part I — Orientation Notebook 1
What a terminal, a shell, and bash each are, and how to run your first commands and find help on your own.
Raymond Amador v1.0.0 · CC BY 4.0 (text) / MIT (code)

What this notebook is about#

This is the first step, and it assumes the truest beginning: that you have never opened a terminal, and that you would like to. No prior command-line experience is taken for granted, and no physics is needed: not here, not anywhere in this course. Later notebooks borrow real scientific files to practise on, but they are only ever text to operate on; you will never need to know what they mean.

A confession about the premise: “the terminal” has a reputation for being arcane, a black rectangle for people with strong opinions about keyboards. It is not. It is one of the simplest tools you will ever use: a place to type the name of a thing you want done and read back what happened. This course exists because students arrive at the graduate Molecular and Materials Modelling course with wildly uneven footing. Some are fluent at the shell; some have never opened one; and nothing computational can really begin until that gap is closed. We close it here.

First, the lay of the land#

Three words get used interchangeably and shouldn’t be. Pulling them apart now saves confusion later.

  • The terminal is the window: the program that draws the text and takes your keystrokes. It is a viewport, nothing more.

  • The shell is the program running inside that window. It reads the command you type, works out what you meant, and asks the operating system to carry it out. bash is one such shell, the one this course teaches and the default on most Linux systems.

  • The operating system does the actual work: it owns the files, the memory, the hardware, and it hands results back up the chain.

So a command you type travels: from you, into the terminal, which passes it to the shell (bash), which asks the operating system to do the thing. The answer comes back the same way.

You Terminal (the window) Shell — bash Operating system (does the work)

That is the whole mental model you need for now. We are not going to talk about processes or kernels; you can drive a car without a theory of combustion.

Getting a shell#

This page is for reading: every grey cell below is a real command and its real output. To practise, you want a shell of your own to type into, and the fastest one needs nothing installed at all.

Practice here → open a live terminal

▶ Launch a live bash terminal — a real, full-screen bash session in your browser, with this course’s files already in place. Nothing to install. The first launch takes a minute to warm up; the session is temporary, so type freely and break nothing.

If the terminal ever fails to load, open JupyterLab instead and start a Terminal from its launcher.

If you would rather use your own machine, you already have a terminal:

  • macOS: open Terminal (Applications → Utilities, or Spotlight “Terminal”).

  • Linux: open the terminal app your desktop ships (often Ctrl+Alt+T).

  • Windows: install WSL (Windows Subsystem for Linux), which gives you a real bash.

And this is the quiet point of the whole notebook: the grey cells below are a live bash session too. Every command in them was really run, and the text beneath each one is really what bash printed. Reading down the page, you are already watching a shell work.

The prompt and the anatomy of a command#

When a shell is ready for you, it prints a prompt and waits. A prompt often ends in $ and may show your username, the machine, and where you are, for example you@laptop:~$. Whatever it shows, the $ is the shell saying “your turn”.

You answer by typing a command and pressing Enter. Nearly every command has the same three-part shape, and learning to see it is most of the battle:

command   [options]   [arguments]
   |           |            |
 what to     how to     what to
   do        do it      do it to
  • The command is the program’s name: what you want done.

  • Options (also called flags) tune how it runs. They usually start with a dash: -l, --all. Most are optional.

  • Arguments are what the command acts on: a file, some text, a name.

Here is the smallest possible example. The command is echo; it has no options; its single argument is the word hello:

echo hello
hello

echo did exactly one thing: it printed its argument back to you. Hold on to the three words (command, option/flag, argument), because the entire course is built on them.

Your first commands#

Each new command below comes as a command card: what it does, the handful of flags worth knowing, and where to look for the rest. You are not meant to memorise these. You are meant to recognise the shape and know how to look things up, which is the next section’s whole subject.

echoprint its arguments back to standard output.
-ndo not add the trailing newline
-einterpret backslash escapes such as \n (newline) and \t (tab)
more: help echo
echo "Hello from the shell!"
Hello from the shell!
echo -e "two\tcolumns\nand a second line"
two	columns
and a second line
pwdprint the working directory: where you currently are in the filesystem.
more: man pwd
pwd
/home/runner/work/bash-primer/bash-primer/notebooks/01-orientation
whoamiprint the username the shell is running as.
more: man whoami
whoami
runner
dateprint the current date and time.
+FORMATprint using a format string — %F is the date as YYYY-MM-DD, %T the time as HH:MM:SS
more: man date · date --help
date
Mon Jul 20 06:06:41 UTC 2026
date +"%F %T"
2026-07-20 06:06:41
clearwipe the visible screen, giving you a clean prompt.
more: man clear, or just press Ctrl+L

There is nothing to print here: clear works by sending the terminal a short control code that means “blank yourself”. In a notebook there is no screen to blank, so we look at the code it would send instead (the ^[ is the escape character):

TERM=xterm clear | cat -v
^[[H^[[2J^[[3J
historylist the commands you have run, newest last, each with a number.
-cclear the history list
more: help history · re-run entry N with !N, or search with Ctrl+R

In your own shell, history fills up as you type. Here we seed it with a couple of entries so there is something to show:

history
    1  echo "Hello from the shell!"
    2  pwd
    3  whoami
    4  date +"%F"
    5  { echo $?; } 2>/dev/null
    6  history

Getting help — the most important skill in the course#

Nobody memorises flags. Not your instructor, not the people who wrote these tools. What a fluent user actually knows is narrower and far more useful: that a flag probably exists for what they want, and how to surface it in ten seconds. That skill, looking it up, is worth more than any list you could cram, and it is the one this course returns to again and again. Three tools cover almost everything.

manopen the full manual page for a command.
-k wordsearch every manual's summary line for a keyword (same as apropos) — for when you don't know the command's name yet
more: press q to quit the manual; man man documents man itself

A manual page is thorough and a little dense; you skim it, you do not read it like a novel. Here are the first lines of the page for ls (we tidy the formatting with col -b and take only the top with head):

man ls | col -b | head -n 8
LS(1)				 User Commands				 LS(1)
NAME
       ls - list directory contents
SYNOPSIS
       ls [OPTION]... [FILE]...

The second tool is not a command at all but a flag, --help: most external commands accept it and print a short usage summary. It is quicker than man for a fast reminder, and it ships with the command itself, so it is almost always there.

date --help | head -n 5
Usage: date [OPTION]... [+FORMAT]
  or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display date and time in the given FORMAT.
With -s, or with [MMDDhhmm[[CC]YY][.ss]], set the date and time.
Watch out: a few commands — echo, cd, history — are built into bash itself rather than being separate programs. Most builtins still take --help, but echo is a trap: echo --help just prints the words --help! The reliable way to read a builtin's help is to ask bash directly with help: try help echo. (We use exactly this in Exercise 4.)
tldrshow a few practical, copy-paste examples for a command, skipping the exhaustive manual.
more: may need installing (brew install tldr, npm install -g tldr); when it is missing, --help is always there

tldr is a community project, so it is not guaranteed to be on every machine, which is the whole reason --help is worth knowing: it ships with the command itself and is always available. When in doubt, reach for --help first.

Exercises#

From here on, each exercise follows the same rhythm: a short task, a place for your answer, and an automatic check that confirms the result with a green ✓. On the published page the answer code is hidden: you see the problem and the checkmark, and the worked solutions are available on request (see the foot of the notebook).

Exercise 1 (worked) — Speak to the shell#

Print a friendly greeting with echo, then print today’s date in ISO form (YYYY-MM-DD) using date with a format string.

Hello from the shell!
2026-07-20
 today's date is in ISO 8601 form, YYYY-MM-DD

Exercise 2 (your turn) — Who and where am I#

Use whoami and pwd to find out who the shell thinks you are and where you are standing, then combine both into a single line that reads I am USER in DIR. (Hint: a command in $( ) is replaced by its output, so echo "... $(whoami) ..." drops your username straight into the sentence.)

I am runner in /home/runner/work/bash-primer/bash-primer/notebooks/01-orientation
 the line is non-empty and names you (runner)

Exercise 3 (worked) — Read the manual#

Pure tool literacy, no science in sight. Consult the help for ls (the list-files command) and find out what two of its most common flags do: -l and -a. The quickest route is ls --help; the fuller one is man ls.

ls --help | grep -E '^[[:space:]]*-(a|l)[ ,]'
  -a, --all                  do not ignore entries starting with .
  -l                         use a long listing format
-l  long format: one entry per line, with permissions, owner, size, and date
-a  all: include hidden entries (those whose names begin with a dot)
 ls -la runs and produces a listing

Exercise 4 (your turn) — Find a flag yourself#

A gentle taste of the course’s core skill: finding a flag without being told it. You want echo to print something without the usual newline at the end. The flag exists. Find it. Because echo is a builtin, ask bash with help echo (remember the watch-out above), spot the flag, and demonstrate it.

echo: echo [-neE] [arg ...]
      -n	do not append a newline
no trailing newline here
 echo -n suppresses the trailing newline (2 bytes, not 3)

Exercise 5 (your turn, optional) — Recall and reuse#

You rarely retype a command; you fish it back out of your history. Run history to see the list, then, in your own shell, re-run an earlier entry with !N (where N is its number) or hunt for it with Ctrl+R.

    1  pwd
    2  ls -la
    3  date +"%F"
    4  history
 your command history is non-empty

Outlook#

You can now stand in a shell, type a command, read what comes back, and, most importantly, find out what you don’t know on your own. That last skill is the one that compounds. What you cannot yet do is move: every command so far has run wherever the shell happened to drop you. The next notebook gives you the map and the legs: the filesystem, and how to walk through it. It is the ground every later trick stands on, from finding files to extracting numbers from them.

New in the Compendium
  • echo — print its arguments back to standard output.
  • pwd — print the working directory: where you currently are in the filesystem.
  • whoami — print the username the shell is running as.
  • date — print the current date and time.
  • clear — wipe the visible screen, giving you a clean prompt.
  • history — list the commands you have run, newest last, each with a number.
  • man — open the full manual page for a command.
  • tldr — show a few practical, copy-paste examples for a command, skipping the exhaustive manual.

See the full Compendium Scriptorum for every command met so far, and where to find it again.

Take this notebook with you
Open a live terminal from the “Practice here” box above to run everything yourself; nothing to install. The published notebooks ship without worked solutions; if you would like the reference solutions (to teach from or to check your own work), get in touch: hello@ramador.me.