Linux · Lesson 8 of 14

Linux terminal basics

Learn the Linux terminal from zero: the shell, files and paths, and your first commands (pwd, ls, cd, cat). Practise in a safe in-browser terminal.

⏱ 18 min🎯 Beginner🧪 Hands-on practice🎬 Video

By the end, you’ll be able to…

  • Explain what the terminal and the shell are
  • Move around the file system with pwd, ls and cd
  • Read files and get help with cat, less and man

Key words

Terminal
The window where you type commands.
Shell
The program that reads your commands and runs them. Bash and Zsh are common shells.
Directory
Another word for folder.
Path
The address of a file or folder, like /home/student/notes.txt.
Home directory
Your personal folder, written as ~ for short.
Root (/)
The very top of the Linux file system. Everything lives under it.

Why learn the terminal?

Most servers on the internet run Linux, and most of them have no screen or mouse. Security tools, logs and cloud machines are all driven by text commands. The terminal is also fast: one line can do what would take fifty clicks.

The good news: you only need about ten commands to feel at home.

The prompt

student@tuxlab:~$

That means: user student, on a computer called tuxlab, currently in ~ (your home folder). The $ means you’re a normal user. A # would mean you’re root, the all-powerful admin account, so be careful there.

The file system is an upside-down tree

Linux has one top folder called root, written /. Everything hangs below it:

/
├── home/
│   └── student/        ← your home (~)
│       ├── Documents/
│       └── notes.txt
├── etc/                ← system settings
├── var/
│   └── log/            ← log files
└── tmp/                ← temporary files

Your first commands

CommandMeansExample
pwdprint working directory: where am I?pwd
lslist what’s herels -la (long format, include hidden)
cdchange directorycd Documents, cd .., cd ~
catprint a filecat notes.txt
lessscroll through a long file (q to quit)less /var/log/syslog
manthe manual for a commandman ls
mkdir / touchmake a folder / an empty filemkdir lab
clearclean the screenclear

Absolute vs relative paths

  • Absolute paths start at / and work from anywhere: /home/student/Documents.
  • Relative paths start from where you are: if you’re in /home/student, then Documents means the same folder.
  • . means “this folder” and .. means “one folder up”.
  • ~ means “my home folder”.

Hidden files

Files whose names start with a dot, like .bashrc, are hidden from plain ls. Use ls -a to see them. Lots of settings live in hidden files.

Three habits that save hours

  1. Tab completion: type the first few letters of a name and press Tab.
  2. History: press ↑ to bring back earlier commands.
  3. Read before you run: never paste commands from the internet that you don’t understand, especially ones starting with sudo or containing rm -rf.
No Linux computer? No problem.

Use the practice terminal below right now. Later, try a free virtual machine (see Build a safe lab), WSL on Windows, or the beginner wargame OverTheWire Bandit.

🧪 Hands-on

Practice

This is a pretend Linux machine that runs entirely in your browser, so you can’t break anything. Work through the missions. Type help any time.

🎬 Watch

Video: Linux for Hackers (and everyone) – EP 1

LinuxLinux for Hackers (and everyone) – EP 1NetworkChuck · Watch on YouTube

Video by NetworkChuck, hosted on YouTube. It loads only when you press play.

✅ Check yourself

Quick quiz

Q1. You’re in /home/student/Documents. Where does cd .. take you?
Q2. Which command shows hidden files?
Q3. A prompt ends with # instead of $. What does that tell you?
Q4. Is /etc/hostname an absolute or relative path?