Files and folders · Linux and the Command Line
How do you find your way around without a mouse?
Course contentsWhy you need it
Servers have no screen. When a website breaks at night, the engineer on call connects to a Linux machine and has only a terminal: you type a command, it prints an answer. Cloud machines, Docker containers and most build systems work the same way, so this is the first tool of every backend, DevOps and security job.
This terminal is a safe practice copy: nothing you type touches your real computer.
The intuition
Files live in folders inside folders, like a tree upside down. / is the root at the top, and your own folder is /home/learner, written ~ for short.
You are always standing in one folder, the working directory:
pwd: where am I?ls: what is here?cd notes: walk into notes.cd ..goes up one level,cdalone goes home.
Paths that start with / are absolute (from the root). Others are relative to where you stand.
Definition
Working directory
The folder your commands run in. Relative paths start from here; `pwd` prints it.
mkdir, touch, cp, mv, rm
Make a folder, make an empty file, copy, move (or rename), remove. `mkdir -p a/b` makes missing parents too; `rm -r` removes a folder and everything in it.
Examples
Look around
Run it in the lessonEach command prints its answer under the prompt. The prompt itself shows where you are.
pwd
ls
cd notes
ls
cd ..
pwd- L1Home is /home/learner.
/home/learner - L2Three folders.
data logs notes - L3Walk into notes; the prompt changes to ~/notes.
- L5
..is always the folder one level up.
Make, copy, move, delete
Run it in the lessonOrganise the notes: a new folder, a backup copy, a rename and a clean-up.
mkdir -p archive/2025
cp notes/todo.txt archive/2025/todo-backup.txt
mv notes/ideas.txt notes/plans.txt
touch notes/draft.txt
rm notes/draft.txt
ls notes archive/2025- L1-p creates archive and archive/2025 in one go.
- L2cp leaves the original where it was.
- L3mv to a new name in the same folder is a rename.
- L6ls with two folders lists each one.
Common mistakes
rm has no recycle bin
A file removed with rm is gone. Before rm -r, run ls on the same path and read what it lists.
Spaces in names
cd my notes means two words. Quote it: cd "my notes", or avoid spaces in file names altogether.
Quick quiz
1. What does this print?
cd logs
cd ..
cd notes
pwdShow the answer
Answer: A
logs, then back up to home, then into notes.
2. You are in `/home/learner/notes`. Which path points to `/home/learner/logs/app.log`?
Show the answer
Answer: B
Go up one level to home with .., then into logs.
Practice
3 exercises in three steps: predict what a program prints, change a program to meet a new requirement, then write one from scratch. Your code runs in the browser and is checked the moment you submit.
- PredictWhere does it end?
Type exactly what these commands print.
- ModifyFix the backup
These commands should copy
notes/todo.txttobackup/todo.txt, but they fail. Fix them. - WriteTidy the logs
Make a folder
logs/old, movelogs/app.loginto it, and leave an empty filelogs/app.login its place (usetouch).
Practise this lesson
Open the interactive lesson to edit and run these examples and solve the exercises with instant feedback. Free to start, no sign-up.
Terms in this lesson
| Term | Chinese | Definition |
|---|---|---|
| Terminal | 终端 | A window where you type commands and read their output. |
| Working directory | 当前目录 | The folder commands run in; relative paths start here. |
| Absolute path | 绝对路径 | A path from the root, starting with /. |