The Terminal

Chapter 11 — Essential Terminal Skills

You've seen terminal commands throughout this course — for updating software, changing settings, and fixing problems. Now it's time to understand the terminal properly. This chapter covers exactly what you need to be capable at the command line: reading the prompt, navigating the file system, working with files and folders, using sudo safely, and editing text files. You won't become a shell scripter from this chapter, but you'll be able to follow any guide online and handle most everyday tasks confidently.

The terminal is a tool, not a test. You don't have to memorise everything here — keep this page bookmarked and refer back to it. With a few weeks of regular use the most common commands become second nature. Everything else you look up when you need it, just like any other skill.

1. Opening a Terminal

Every Linux desktop has a terminal emulator — an application that gives you a command-line interface. The fastest ways to open one:

  • Ubuntu (GNOME) — press Ctrl+Alt+T, or search for "Terminal" in the Activities overview
  • Linux Mint (Cinnamon) — press Ctrl+Alt+T, or right-click the desktop → "Open Terminal Here"
  • KDE Plasma — press Ctrl+Alt+T (if configured), or search for "Konsole" in the application launcher
  • XFCE — right-click the desktop → "Open Terminal Here", or find "Terminal Emulator" in the application menu
  • Any desktop — search "terminal" in the application launcher; every desktop has one installed
Terminal emulator vs shell. The terminal emulator (GNOME Terminal, Konsole, xterm) is the window. The shell is the program running inside it that interprets your commands — almost always Bash on Linux. When people say "open a terminal" they mean open the terminal emulator; when they say "run this in bash" they mean type it at the prompt in that window.

2. Reading the Prompt

When you open a terminal you see a prompt — a line indicating the shell is ready for input. It looks something like this:

philip @ philip-laptop : ~/Documents $
↑ username ↑ hostname ↑ current directory ↑ $ = normal user
  • username — the account you're logged in as
  • hostname — the name of the computer (from Chapter 6)
  • current directory — where in the file system you are right now. The tilde (~) is shorthand for your home directory (/home/philip)
  • $ symbol — means you're a normal user. A # symbol means you're root (the administrator). You should almost never see # in normal use.

Type a command after the prompt and press Enter to run it. The output appears on the lines below, then a new prompt appears when the command finishes.

3. The Linux File System

Linux has one unified file system tree starting at / (called "root" or "slash"). There are no drive letters like Windows — everything, including additional drives and USB sticks, appears as a folder somewhere under /.

/ ← the root of the entire file system ├── home/ ← user home directories │ └── philip/ ← your home directory (~) │ ├── Documents/ │ ├── Downloads/ │ ├── Desktop/ │ └── .config/ ← hidden config files (dot files) ├── etc/ ← system configuration files ├── var/ ← variable data: logs, databases, mail │ └── log/ ← system log files ├── usr/ ← installed programs and libraries │ └── bin/ ← most user commands live here ├── bin/ ← essential system commands ├── tmp/ ← temporary files (cleared on reboot) ├── dev/ ← device files (disks, USB, etc.) ├── proc/ ← virtual: running processes └── mnt/ media/ ← mount points for drives/USB sticks

The most important location for day-to-day use is your home directory. Everything you create and most software configuration lives under /home/yourusername/, abbreviated to ~ in the prompt and in commands.

Hidden files (called "dot files") start with a dot: .bashrc, .config/, .ssh/. They are hidden by default in the file manager and in ls output. Press Ctrl+H in the file manager to show them, or use ls -a in the terminal.

4. Navigating the File System

# Print Working Directory — where am I now? $ pwd /home/philip # List files and folders in the current directory $ ls Desktop Documents Downloads Music Pictures Videos # List with details (permissions, size, date) $ ls -l # List including hidden files (dot files) $ ls -a # Both — detailed and including hidden files $ ls -la # Change Directory — move into a folder $ cd Documents $ pwd /home/philip/Documents # Go back up one level (.. means "parent directory") $ cd .. # Go to your home directory (three equivalent ways) $ cd $ cd ~ $ cd /home/philip # Go to an absolute path (starts with /) $ cd /etc # Go back to the previous directory (handy for toggling between two locations) $ cd -
Tab completion is your best friend. Start typing a file or folder name and press Tab — the shell completes it for you. If there are multiple matches, press Tab twice to see them all. This saves enormous amounts of typing and avoids typos. Use it constantly.

5. Working with Files and Folders

# Create a directory $ mkdir my-project # Create nested directories in one command (-p = create parents too) $ mkdir -p projects/website/images # Create an empty file $ touch notes.txt # Copy a file $ cp notes.txt notes-backup.txt # Copy a file into a directory $ cp notes.txt Documents/ # Copy a directory and all its contents (-r = recursive) $ cp -r my-project my-project-backup # Move / rename a file $ mv notes.txt notes-renamed.txt # Move a file into a directory $ mv notes.txt Documents/ # Delete a file $ rm old-file.txt # Delete a directory and all its contents (-r = recursive) $ rm -r old-project/
rm is permanent. There is no Recycle Bin, no Trash, no undo. When you rm a file it is gone immediately. Be especially careful with rm -r (recursive delete) — a typo can delete far more than you intended. Always double-check the path before pressing Enter. Never run rm -rf / or rm -rf ~ — these would destroy your entire system or home directory respectively.

6. Viewing File Contents

# Print the entire contents of a file to the screen $ cat /etc/hostname philip-laptop # View a file page by page (press Space to advance, q to quit) $ less /etc/apt/sources.list # Show just the first 10 lines of a file $ head /var/log/syslog # Show just the last 10 lines of a file $ tail /var/log/syslog # Watch a log file update in real time (Ctrl+C to stop) $ tail -f /var/log/syslog # Search inside a file for a word or pattern $ grep "error" /var/log/syslog # Search case-insensitively $ grep -i "wifi" /var/log/syslog
Use less, not cat, for large files. cat dumps everything to the screen at once — on a 10,000-line log file you'll see thousands of lines fly past. less lets you scroll at your own pace. Inside less: /searchterm to search, n for next match, q to quit.

7. sudo — Running Commands as Administrator

Many system tasks — installing software, editing system files, restarting services — require administrator privileges. Linux uses sudo (superuser do) to grant temporary elevated permissions for a single command.

# Run a single command with admin privileges $ sudo apt install vlc [sudo] password for philip: # sudo caches your password for ~15 minutes — you won't be asked again # for subsequent sudo commands in that session # Edit a system file that requires admin access $ sudo nano /etc/hostname # Run as root for multiple commands (exit when done — don't stay as root) $ sudo -i root@philip-laptop:~# root@philip-laptop:~# exit $
sudo tips and cautions:
  • When typing your sudo password, nothing appears on screen — no dots, no asterisks. This is normal; keep typing and press Enter.
  • Only your own account (or other accounts in the sudo group) can use sudo — this protects the system from other users.
  • Copy-pasting sudo commands from the internet can be dangerous. Read what a command does before running it with sudo.
  • If you get "philip is not in the sudoers file", your account needs to be added to the sudo group — ask Chapter 6's user management section.

8. Editing Files with nano

nano is the friendliest terminal text editor — it shows keyboard shortcuts at the bottom of the screen so you don't need to memorise anything to get started. It's available on virtually every Linux system and is what most guides recommend for beginners.

# Open or create a file in nano $ nano myfile.txt # Edit a system file (requires sudo) $ sudo nano /etc/hosts

Inside nano, the bottom two lines show the available commands. The ^ symbol means the Ctrl key:

Ctrl+O
Save (Write Out). Press Enter to confirm the filename.
Ctrl+X
Exit. Asks to save if you have unsaved changes.
Ctrl+W
Search (Where Is). Type your search term and press Enter.
Ctrl+K
Cut the current line (or selected text).
Ctrl+U
Paste (Uncut) the last cut text.
Ctrl+G
Help — full list of shortcuts.
Ctrl+A / Ctrl+E
Jump to start / end of the current line.
Alt+U
Undo last change.
Ctrl+C
Show current line and column number (does NOT copy in nano).
The typical nano workflow: open the file, make your edits, press Ctrl+O then Enter to save, then Ctrl+X to exit. Or just press Ctrl+X — if there are unsaved changes it asks "Save modified buffer?" — press Y then Enter.

9. Terminal Shortcuts That Save Time

ShortcutWhat it does
Tab Auto-complete file/folder names and commands. Press twice to show all matches. Use it constantly.
/ Scroll through command history. Find and re-run a previous command without retyping it.
Ctrl+R Reverse search through command history. Start typing a word from a previous command to find it.
Ctrl+C Cancel (stop) the currently running command. Press this when a command hangs or you change your mind.
Ctrl+L Clear the screen (same as the clear command). Keeps your command history.
Ctrl+A Jump to the beginning of the current command line.
Ctrl+E Jump to the end of the current command line.
Ctrl+U Delete everything from the cursor to the beginning of the line. Quick way to clear a command.
Ctrl+W Delete the word immediately before the cursor.
Ctrl+D Exit the shell / close the terminal (like typing exit).
Ctrl+Shift+C Copy selected text from the terminal (not Ctrl+C — that cancels the command!).
Ctrl+Shift+V Paste into the terminal.

10. Pipes and Redirection

Two features of the shell that you'll encounter in guides and find genuinely useful:

The pipe — |

A pipe sends the output of one command as the input to another. This lets you chain commands together to filter or process output.

# Show running processes and search for a specific one $ ps aux | grep firefox # List files and search the output for .log files $ ls /var/log | grep "syslog" # See command history and search it $ history | grep "apt install" # Count how many lines of output a command produces $ ls /usr/bin | wc -l 1847

Output redirection — > and >>

Instead of printing output to the screen, redirect it to a file.

# Save command output to a file (overwrites if file exists) $ ls -la > file-list.txt # Append output to an existing file (doesn't overwrite) $ echo "New entry" >> notes.txt # Discard output entirely (send to /dev/null — the black hole) $ some-noisy-command > /dev/null 2>&1

11. A Few More Useful Commands

System information
uname -rShow current kernel version
uptimeHow long the system has been running
df -hDisk usage — how full each partition is
free -hRAM usage — total, used, available
topLive view of running processes and CPU/RAM use. Press q to quit.
htopNicer version of top (install with apt if missing)
Finding things
find ~ -name "*.txt"Find all .txt files in your home directory
grep -r "word" ~/DocumentsSearch for "word" inside files recursively
which firefoxFind where a command/program is installed
man lsShow the manual page for any command. Press q to quit.
ls --helpQuick help for a command (faster than man)
Services and processes
sudo systemctl status nginxCheck if a service is running
sudo systemctl restart nginxRestart a service
sudo systemctl enable nginxStart a service automatically on boot
kill 1234Stop a process by its PID number
killall firefoxStop all processes named firefox
Permissions
chmod +x script.shMake a file executable
chmod 644 file.txtrw-r--r-- (owner write, others read)
chown philip file.txtChange file owner to philip
ls -lShow permissions for files in current directory
When a command fails: read the error message — Linux error messages are usually informative. "Permission denied" means you need sudo. "command not found" means the program isn't installed (try sudo apt install commandname). "No such file or directory" means you've typed a path that doesn't exist — check spelling and case (Linux filenames are case-sensitive).

Chapter Summary

SkillKey commands
Navigate pwd (where am I), ls (list files), cd folder (enter folder), cd .. (go up), cd ~ (go home)
Files & folders mkdir (create dir), touch (create file), cp (copy), mv (move/rename), rm (delete — permanent!)
View files cat (print), less (page by page), head/tail (first/last lines), grep (search inside)
Admin sudo command — runs command as administrator. Password cached for ~15 minutes. Nothing shows when typing the password.
Edit files nano filename — Ctrl+O to save, Ctrl+X to exit, Ctrl+W to search.
Shortcuts Tab (complete), ↑↓ (history), Ctrl+C (cancel), Ctrl+L (clear), Ctrl+R (search history)
Pipes cmd1 | cmd2 — send output of cmd1 to cmd2. > file — redirect output to file. >> file — append to file.
Get help man command — full manual. command --help — quick reference. Error messages usually tell you exactly what went wrong.
Next: Chapter 12 — Users, permissions & security. We look at Linux user accounts and groups in more depth, understand file permissions (chmod and chown), sudo configuration, and how to set up the UFW firewall.