Before you start
- A computer running Linux (Ubuntu, Debian, Linux Mint, Fedora…), a virtual machine, or a server you are connected to over SSH
- On Windows, WSL (Windows Subsystem for Linux) is also perfectly fine for practising
- No prior knowledge: we start from scratch
In plain words
The terminal is talking to the computer in writing instead of pointing at things. Instead of clicking a folder, you write "go into this folder"; instead of dragging a file to the bin, you write "delete it". It is faster once you know the words, and about thirty words are enough to get by.
The command line is intimidating at first, but about thirty commands cover 90% of everyday needs: moving around, managing files, installing software, monitoring the machine. This guide groups them by task, each with an example you can type as is.
The examples are given for Debian and Ubuntu. Almost everything works the same on other distributions; only software installation differs (see part 7).
1. Terminal basics
Open a terminal: on Ubuntu, Ctrl + Alt + T, or search for "Terminal" in your applications. You see a line like this one, called the prompt:
spo@laptop:~$
It shows the user (spo), the machine name (laptop) and the folder you are in (~ means your home folder). The $ marks a regular user; a # marks the administrator account, root.
A command is always built the same way:
command -options arguments
ls -l /home
Here, ls is the command (list), -l the option (detailed view) and /home the argument (the folder to list). Linux is case-sensitive: Documents and documents are two different folders.
Three habits that save a lot of time
Tab: completes a command or file name automatically. Press it twice to see the options.↑and↓: bring back previous commands.Ctrl+C: stops the running command. In a terminal, this shortcut does not copy: to copy, useCtrl+Shift+C, andCtrl+Shift+Vto paste.
2. Finding your way around
| Command | What it does | Example |
|---|---|---|
pwd |
Shows the folder you are in | pwd |
ls |
Lists the contents of a folder | ls |
ls -lah |
Detailed list, hidden files included, readable sizes (KB, MB) | ls -lah ~/Documents |
cd |
Changes folder | cd /etc |
cd .. |
Goes up one level | cd .. |
cd ~ or cd |
Goes back to your home folder | cd |
cd - |
Goes back to the previous folder | cd - |
Two ways to write a path:
- Absolute, from the root of the system, starts with
/:/home/spo/Documents. - Relative, from the current folder:
Documents/invoices.
Files whose name starts with a dot (.bashrc, .ssh) are hidden: only ls -a shows them.
3. Managing files and folders
| Command | What it does | Example |
|---|---|---|
mkdir |
Creates a folder | mkdir projects |
mkdir -p |
Creates a whole tree at once | mkdir -p projects/2026/photos |
touch |
Creates an empty file | touch notes.txt |
cp |
Copies a file | cp notes.txt notes-copy.txt |
cp -r |
Copies a folder and everything in it | cp -r projects projects-backup |
mv |
Moves or renames | mv notes.txt archive/ or mv draft.txt final.txt |
rm |
Deletes a file | rm old.txt |
rm -r |
Deletes a folder and everything in it | rm -r old-folder |
rm -i |
Asks for confirmation before each deletion | rm -i *.log |
The * character stands for "anything": *.jpg means every file ending in .jpg. If a name contains spaces, put it in quotes: cd "My documents".
No recycle bin in the terminal
rm deletes for good, without going through the bin. Before an rm with *, first run an ls with the same pattern to see exactly what will be deleted. And never type a command containing rm -rf / found on the internet: it erases the whole system.
4. Reading a file
| Command | What it does | Example |
|---|---|---|
cat |
Shows a short file in full | cat /etc/hostname |
less |
Browses a long file page by page (q to quit, /word to search) |
less /etc/services |
head |
Shows the first lines (10 by default) | head -n 20 file.csv |
tail |
Shows the last lines | tail -n 50 file.csv |
tail -f |
Follows a file live (ideal for logs), Ctrl + C to stop |
tail -f /var/log/apache2/access.log |
wc -l |
Counts lines | wc -l list.txt |
Where are the system logs?
On Ubuntu, they are still written to /var/log/syslog. Since Debian 12, that file no longer exists by default: logs are read with journalctl -e (the most recent) and journalctl -f (live), which also works on Ubuntu, Fedora and Arch.
5. Editing a file with nano
nano is the simplest text editor, installed almost everywhere:
nano notes.txt
You type the text directly. The shortcuts are listed at the bottom of the screen (^ means Ctrl):
Ctrl+OthenEnter: save;Ctrl+X: quit;Ctrl+W: search;Ctrl+K: cut the line,Ctrl+U: paste it.
For a system file, add sudo in front: sudo nano /etc/hosts. Make a copy before editing a configuration file: sudo cp /etc/hosts /etc/hosts.bak.
Stuck in vi or vim?
If another editor opens and nothing behaves as expected, it is probably vi. Press Esc, type :q! then Enter to quit without saving.
6. Finding a file or some text
| Command | What it does | Example |
|---|---|---|
find |
Finds files by name (-iname ignores case) |
find ~ -iname "*invoice*" |
find -size |
Finds large files | find ~ -size +500M |
grep |
Searches for a word in a file | grep "error" log.txt |
grep -rin |
Searches a whole folder, ignoring case, with line numbers | grep -rin "password" ~/scripts |
which |
Shows where a program is located | which python3 |
7. Installing and updating software
Each family of distributions has its own package manager. It downloads software from the official repositories, checked by the distribution: that is the method to prefer over downloading files from websites.
| Action | Debian, Ubuntu, Mint | Fedora, Rocky, Alma | Arch, Manjaro |
|---|---|---|---|
| Update the whole system | sudo apt update && sudo apt upgrade |
sudo dnf upgrade |
sudo pacman -Syu |
| Install | sudo apt install htop |
sudo dnf install htop |
sudo pacman -S htop |
| Uninstall | sudo apt remove htop |
sudo dnf remove htop |
sudo pacman -R htop |
| Search | apt search htop |
dnf search htop |
pacman -Ss htop |
On Debian and Ubuntu, apt update refreshes the list of available software and apt upgrade installs the updates: always run both, in that order. sudo apt autoremove then removes packages that are no longer needed.
8. Users and permissions
sudo runs a command with administrator rights. It asks for your password (not root's), and nothing is displayed while you type: that is normal.
| Command | What it does | Example |
|---|---|---|
whoami |
Shows your user name | whoami |
id |
Shows your groups (the sudo or wheel group grants admin rights) |
id |
passwd |
Changes your password | passwd |
chmod |
Changes a file's permissions | chmod +x script.sh |
chown |
Changes a file's owner | sudo chown spo:spo file.txt |
In an ls -l listing, the first column shows the permissions, for example -rwxr-xr--. After the first character (- for a file, d for a folder), you read three groups of three letters: the permissions of the owner, the group, then everyone else. r = read, w = write, x = execute (or enter, for a folder).
They are often written as numbers: r = 4, w = 2, x = 1, added together. The two values to know:
chmod 644 file: you read and write, others only read (ordinary files);chmod 755 folder: you do everything, others read and enter (folders, scripts).
Never chmod 777
A tutorial that suggests chmod 777 to "fix a permission problem" makes the file writable by everyone. Look for the right owner with chown instead.
9. Monitoring the system
| Command | What it does | Example |
|---|---|---|
df -h |
Free space on each disk | df -h |
du -sh |
Size of a folder | du -sh ~/Downloads |
du -sh * | sort -h |
Size of each item in the folder, smallest to largest | du -sh * | sort -h |
free -h |
Memory used and available | free -h |
top or htop |
Running processes, live (q to quit). htop is easier to read but installed separately |
htop |
ps aux |
Lists all processes | ps aux | grep firefox |
kill |
Stops a process by its number (PID) | kill 4321 |
uptime |
How long the machine has been running, and its load | uptime |
uname -a |
Linux kernel version | uname -a |
cat /etc/os-release |
Distribution name and version | cat /etc/os-release |
If kill is not enough, kill -9 4321 forces the process to stop, without giving it time to save: keep it as a last resort.
10. Managing services
Services (web server, SSH, printing…) run in the background. On almost every current distribution, they are controlled with systemctl:
systemctl status ssh # service status
sudo systemctl restart ssh # restart
sudo systemctl stop ssh # stop
sudo systemctl start ssh # start
sudo systemctl enable ssh # start automatically at boot
journalctl -u ssh -n 50 # its last 50 messages
The service name varies by distribution: ssh on Debian and Ubuntu, sshd on Fedora or Rocky. Pressing Tab after systemctl status suggests the available names.
To shut down or restart the machine: sudo poweroff and sudo reboot.
11. Networking in a few commands
| Command | What it does | Example |
|---|---|---|
ip a |
The machine's IP addresses | ip a |
ip r |
Default gateway (your box or router) | ip r |
ping -c 4 |
Tests whether a machine answers (4 attempts) | ping -c 4 1.1.1.1 |
ss -tulpn |
Open ports listening on the machine (with sudo to see the programs) |
sudo ss -tulpn |
curl -I |
Tests a website and shows its response | curl -I https://example.com |
ssh |
Connects to another machine | ssh spo@192.168.1.20 |
scp |
Copies a file to another machine | scp photo.jpg spo@192.168.1.20:~/ |
To go further: network troubleshooting and securing SSH access.
12. Archiving and compressing
tar -czf backup.tar.gz Documents/ # create a compressed archive
tar -tzf backup.tar.gz # list its contents
tar -xzf backup.tar.gz # extract it into the current folder
unzip archive.zip # extract a .zip
To remember tar: c = create, x = extract, t = list, z = gzip compression, f = file name (always last). unzip is not always installed: sudo apt install unzip.
13. Combining commands
The real power of the terminal is chaining commands:
| Symbol | Effect | Example |
|---|---|---|
| |
Sends one command's output to the next | ls -l | less |
> |
Writes the output to a file (overwrites it) | ls > list.txt |
>> |
Appends the output to the end of a file | date >> log.txt |
&& |
Runs the second command only if the first succeeded | sudo apt update && sudo apt upgrade |
And to find what you already typed:
history: lists the latest commands;Ctrl+Rthen a few letters: searches the history;clearorCtrl+L: clears the screen.
14. Getting help
man ls: the full manual of a command (qto quit,/wordto search);ls --help: a summary of the options, quicker to read;tldr ls: concrete examples rather than a manual, installed withsudo apt install tldron Ubuntu (elsewhere,apt search tldrgives the package name).
Key takeaways
Tabto complete,↑to recall,Ctrl+Cto stop.pwd,ls,cdto find your way;cp,mv,rm,mkdirfor files.rmdoes not use the bin: check withlsfirst.- Regular updates:
sudo apt update && sudo apt upgrade(or your distribution's equivalent). sudoonly when needed, and never a command copied from the internet without understanding it.