Module 1 · Lesson 1 of 14

Linux, the shell and getting help

Learn the interface you will use for the whole program: kernel and user space, the shell, command lookup, and finding help on your own machine.

  • Beginner
  • 8 min read
  • 40 min lab
  • Ubuntu 24.04 · no board needed
By Eslam El Hefny · updated

By the end you can

  • Describe how the kernel, user space and a distribution relate, with one example of each.
  • Tell a terminal, a shell and a console apart in one sentence each.
  • Trace how the shell finds and starts a command, and explain why cd must be a builtin.
  • Answer any "how do I use X?" question with man, help, --help, apropos and type.
  • Re-run and complete commands faster with Tab, history expansion and Ctrl+R.
Watch first, then read the lesson and try the lab. Videos play from YouTube in privacy-enhanced mode, only after you press play.
Before you start

No prerequisites. Use Ubuntu 24.04 in WSL2, a VM or a container. You do not need a board for this lesson.

01

Why the command line?

1 min read

You already depend on Linux

Every server on the internet, almost every phone, your Wi-Fi router, many cars and the machines in factories run Linux underneath. The people who build these systems talk to Linux in one main way: by typing. A terminal looks old-fashioned, but it is the fastest, most precise way to control a computer, and the only way when the computer has no screen - like a sensor board in a field. This program takes you from your first command all the way to writing Linux drivers and shipping a device. Module one starts here, at the shell.

02

What is Linux, really?

2 min read

Kernel, user space, distribution

Think of three layers. At the bottom is hardware: CPU, memory, disk, network card. Above it sits the kernel - this is Linux. The kernel shares the CPU between programs, gives each program its own memory, and talks to devices through drivers. Above the kernel live ordinary programs: the shell, ls, a web server. This is user space. A distribution (Ubuntu, Debian, Fedora) is the kernel plus a chosen set of user-space programs and a package manager, tested to work together.

Bash
uname -r
grep PRETTY /etc/os-release
Linux, layer by layerLinux, layer by layerLinux, layer by layerA conceptual stack; applications can also invoke system calls directly.User spaceApplicationsC librarySystem-call interfaceBoundaryKernel spaceSchedulerMemoryVFSNetworkDriversHardwarePlatformKernel subsystems cooperate; boxes show responsibilities rather than a serial execution path.
User-space programs call into the kernel, which manages hardware through drivers. A distribution packages the kernel and user space.

System calls: the guarded door

User-space programs cannot touch hardware directly. They must ask the kernel, through a narrow, guarded door called a system call: "please read this file", "please start this program". The kernel checks the request, then acts. This door matters all through the program: you will walk through it in this session, write code that uses it in module two, and build it yourself in module three.

Go deeper: same kernel, different build

A common misconception: "Linux on a board is a different Linux." It is not. It is the same kernel source, configured differently, with a smaller user space. A Raspberry Pi and your laptop run the same Linux; the difference is which drivers are enabled and how much user space is installed. What you learn on your laptop transfers directly to devices. In module four you will build that smaller system yourself.

03

Terminal, shell, console

1 min read

The terminal just draws text

When you open that black window you are actually looking at two programs working together. The terminal (or terminal emulator) is a window program. It draws text, takes your keystrokes and sends them on. That is all it does - it does not understand commands. On Ubuntu it might be GNOME Terminal or Konsole; on Windows WSL, a terminal hosts the Linux shell.

The shell understands commands

The shell is the program that understands commands. On Ubuntu it is usually Bash. It reads a line, figures out what you mean, and asks the kernel to run programs. Your login shell is recorded in the SHELL variable. The shell is a normal program, running with its own process id, that you can see with ps.

Bash
echo $SHELL
ps -p $$

The console, and the serial console

Console historically meant the physical screen and keyboard attached to a machine. Today it usually means a text login without a desktop - or, very important for embedded work, the serial console: a single wire carrying a terminal session from a device that has no screen. Later modules (M4 onward) talk to boards this way. Remember the split: terminal draws, shell understands, kernel does.

04

What happens when you press Enter

2 min read

1the line becomes words

You type ls -l /etc and press Enter. The terminal does not run anything - it hands the characters to the kernel, which wakes Bash with the line. Bash then splits the line into words on spaces. The first word, ls, is the command name; -l and /etc are arguments - extra information for the command.

2what is `ls`, and where?

Bash must answer one question: what is ls? It checks, in order: aliases (shortcuts), functions, builtins (commands built into Bash), a hash table of paths it already found, then each directory in $PATH left to right. On Ubuntu, ls is an alias for ls --color=auto - that is why listings are coloured. The real program is at /usr/bin/ls.

Bash
type -a ls
type -a echo

3fork - copy the shell

Bash cannot simply become ls - then your shell would be gone. So it asks the kernel to fork: make an almost exact copy of itself. Now two Bash processes exist: the parent (the shell you are using) and the child (a copy). The child is the one that will become ls.

4exec - become another program

The child then calls exec: "kernel, replace my program with /usr/bin/ls". It is the same process, with the same process id, but now it runs ls with the arguments you typed. The shell's copy has been replaced; the original shell is still there, untouched, waiting.

5wait and the exit status

ls runs, writes its output to the terminal, then exits with a status number: 0 means success, non-zero means failure (127 = not found, 2 = a usage or path error). The parent shell has been waiting; the kernel tells it the child finished, and Bash stores the number in a variable called $?. Then it prints a fresh prompt - full circle.

Bash
ls /etc >/dev/null; echo $?
ls /nope; echo $?
nosuchcmd; echo $?

Go deeper: why `cd` must be a builtin

Try cd /tmp. Bash does not fork a child for this - cd is a builtin. Why? Every process has its own current directory. If a child changed directory and then exited, the parent shell would still be where it was - so cd could never work as a separate program. It runs inside the shell itself. This is also why man cd has no entry: builtins are documented with help cd, not the manual.

Bash
man cd
help cd | head -3
05

Getting help

1 min read

--help and the manual

Professionals do not memorise every option - they look things up in seconds. command --help prints a quick summary. The full reference is the manual: man command. A man page opens in less: Space pages forward, /word searches, n finds the next match, q quits. The manual is divided into numbered sections - section 1 is user commands, 2 is system calls, 5 is file formats.

Bash
ls --help | head -5
man -P cat ls | head -8
man -P cat ls | grep -i human

`apropos` and `type`: finding and identifying

When you do not know the command name, search the manual's descriptions with apropos (or man -k). When you want to know what a name is, use type: it tells you alias, builtin or path. type -a shows every match in lookup order.

Bash
apropos -a file system space
man -f write
type python3
type ll
Captured lab output
$ type -a echo
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo
$ which echo
/usr/bin/echo

Builtins use `help`, not `man`

Builtins have no man page. man cd returns "No manual entry for cd". Builtins are documented inside Bash itself with help. So the decision chart is: know the name -> --help then man; it is a builtin -> help; do not know the name -> apropos; not sure what it is -> type.

06

Working fast

1 min read

Tab completion

Good shell users type surprisingly little. Tab completion: type the first few letters of a path or command and press Tab. Bash completes it if there is one match; press Tab twice to see all options. Tab also catches typos - if nothing completes, the path probably does not exist.

History and reverse search

The shell remembers your commands. Up arrow brings back the previous one. history lists them numbered, and !7 re-runs entry 7. Ctrl-R starts a reverse search: type part of an old command and Bash finds it; press Ctrl-R again for older matches, Enter to run.

Try it: the help-desk scavenger hunt

Answer 15 questions using the system’s own help tools. Record the command that proves each answer, then download your notes.

Open the exercise

Last updated by Eslam El Hefny.
Spotted a mistake? Fix it and your name appears here.

Key takeaways

  • Linux is the kernel; a distribution adds user-space programs on top.
  • The terminal draws text, the shell interprets commands, the kernel does the work.
  • Bash looks up a name as alias, builtin or function, then the hash table, then each PATH directory.
  • Builtins like cd must run inside the shell; programs run after fork and exec.
  • man, help, --help, apropos and type answer almost any question offline.

Reflect

  1. Explain to a colleague, in two sentences, how the shell finds and starts a command.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?

On a real board

Log in to your Raspberry Pi or lab board over SSH or the serial console and repeat type -a, man -k and help. Small images often lack manual pages: notice how you find help when man is missing.

Practise this lesson14 exercises · 20-question quiz · 12 interview questions · spaced review

References and further reading

Official documentation first. Links checked when the lesson was published.

Find your next step

↑ ↓ to move · Enter to open · Esc to close