Everyone Can Learn Program
中文 Start learning
Core · LinuxLesson 1 of 6Free to read

Files and folders · Linux and the Command Line

How do you find your way around without a mouse?

Course contents

Why 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, cd alone 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

Each command prints its answer under the prompt. The prompt itself shows where you are.

pwd
ls
cd notes
ls
cd ..
pwd
Step by step
  1. L1Home is /home/learner./home/learner
  2. L2Three folders.data logs notes
  3. L3Walk into notes; the prompt changes to ~/notes.
  4. L5.. is always the folder one level up.

Make, copy, move, delete

Run it in the lesson

Organise 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
Step by step
  1. L1-p creates archive and archive/2025 in one go.
  2. L2cp leaves the original where it was.
  3. L3mv to a new name in the same folder is a rename.
  4. 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
pwd
  1. A
    /home/learner/notes
  2. B
    /home/learner/logs/notes
  3. C
    /notes
Show 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`?

  1. Alogs/app.log
  2. B../logs/app.log
  3. C/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.

  1. PredictWhere does it end?

    Type exactly what these commands print.

  2. ModifyFix the backup

    These commands should copy notes/todo.txt to backup/todo.txt, but they fail. Fix them.

  3. WriteTidy the logs

    Make a folder logs/old, move logs/app.log into it, and leave an empty file logs/app.log in its place (use touch).

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

TermChineseDefinition
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 /.