Show contents
Chapter 1 of 7 · 20 min
The terminal and the file tree
By the end of this chapter, you'll be able to
- Explain what a terminal, a shell and a prompt are
- Find your way around the file tree with pwd, ls and cd
- Tell an absolute path from a relative path
- Create folders and files, and display their contents
Terminal, shell and prompt
The terminal is the window where you type text. The program that reads your commands and runs them is called the shell: on Linux, it is most often bash. When it is waiting for a command, it shows a prompt, for example:
awa@server:~$
It reads: the user awa, on the machine server, in the folder ~ (the user's home folder), and $ indicates an ordinary user. In this course, commands are written without the prompt: you only type what follows the $, then Enter.
To open a terminal: the “Terminal” application on Linux and macOS; on Windows, install WSL (the free Windows Subsystem for Linux) from Microsoft's official documentation. The labs in this course also work directly in your browser.
The file tree: where am I?
On Linux, all files are stored in a single tree of folders, which starts at the root /. Your home folder is usually /home/ followed by your name. At any moment, the shell is in a current folder. Three commands to find your bearings:
pwd(print working directory) shows the current folder;ls(list) lists its contents;cd(change directory) changes folder.
$ pwd
/home/awa
$ ls
Documents Pictures project
$ cd project
$ pwd
/home/awa/project
Absolute and relative paths
A path designates a file or folder in the tree:
- an absolute path starts with
/and goes from the root:/home/awa/project/notes.txt; - a relative path starts from the current folder: from
/home/awa, the same file is writtenproject/notes.txt.
Three shortcuts to know: . means the current folder, .. the parent folder (the one above), and ~ your home folder. cd on its own takes you back home.
Both paths lead to the same place: one depends on the current folder, the other does not.
Text description of the animation
- The path does not start with /: it is relative, the shell starts from the current folder.
- .. means the parent folder: we go up one notch.
- We go down into the photos subfolder.
- Then into 2026.
- Both paths lead to the same place: one depends on the current folder, the other does not.
Creating folders and files
mkdir (make directory) creates a folder; with -p, it also creates the missing intermediate folders. touch creates an empty file. To write text into a file, echo followed by > redirects what it prints into the file, and cat displays a file's contents:
mkdir -p shop/products
echo "Shea butter soap: 1500 FCFA" > shop/products/soap.txt
cat shop/products/soap.txt
Shea butter soap: 1500 FCFA
Careful: > replaces the file's contents. To add a line at the end, use >>:
echo "Shea butter: 2500 FCFA" >> shop/products/soap.txt
cat shop/products/soap.txt
Shea butter soap: 1500 FCFA
Shea butter: 2500 FCFA
Options change a command's behaviour: ls -a also shows hidden files (whose name starts with a dot), ls -l displays the long format, with permissions, size and date. You can combine them: ls -la. To get help on a command on a real system, type man ls (and q to quit) or ls --help.
Your turn
Mini-lab: your first look aroundTerminal simulator
Terminal
Click “Run”: the commands run in a fresh terminal, in your home folder /home/awa. Type “help” for the list of commands.Teaching simulator: it reproduces the essential Linux commands in your browser, with nothing to install · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor
This lab is a simulator: it reproduces the essential Linux commands in your browser, with nothing to install. Add lines, create other folders, type help to see the available commands.
Worked exercise
Worked exercise: a book club's folder
Create the following structure in the current folder: a club folder, containing books and members. In books, create a file to-read.txt containing two lines: “The Dark Child” then “So Long a Letter”. Then display the file's contents without leaving the current folder.
Hint 1
mkdir -p accepts several paths at once.Hint 2
>, the second with >>, and relative paths like club/books/to-read.txt.Show the solution and common mistakes
mkdir -p club/books club/members
echo "The Dark Child" > club/books/to-read.txt
echo "So Long a Letter" >> club/books/to-read.txt
cat club/books/to-read.txt
The Dark Child
So Long a Letter
Relative paths avoid moving around: the current folder does not change.
Common mistakes:
- Using
>for the second title: it replaces the first, and the file only contains one line. - Forgetting
-pwhen creatingclub/bookswhileclubdoes not exist yet:mkdirrefuses with “No such file or directory”.
Summary
- 1The shell (often bash) reads and runs the commands typed in the terminal.
- 2pwd shows the current folder, ls lists its contents, cd changes folder.
- 3An absolute path starts from the root /, a relative path from the current folder; .. goes up one level.
- 4mkdir -p creates folders, echo text > file writes, >> appends, cat displays.
- 5Avoid spaces in file names, or put them in quotes.
Your progress is saved on this device. Create a free account to keep your progress on all your devices.