A beginner-friendly guide to navigating the terminal, managing files, controlling processes, and writing shell scripts
The CLI (Command Line Interface) β also called the terminal or shell β is a text-based way to control your computer. Instead of clicking buttons, you type commands and press Enter. Every Linux server, every Docker container, and every cloud machine is controlled through a command line β which is why learning it unlocks practically everything else in programming.
| Scenario | Without the CLI | With the CLI |
|---|---|---|
| Rename 200 files | Right-click each file individually... for an hour | rename / mv in a loop β done in seconds |
| Configure a server | Need a desktop environment and a web panel | ssh in and vim the config β works headless |
| Find a log error | Open the file, scroll forever | grep ERROR app.log β instantly narrowed |
| Concept | What it is |
|---|---|
| Terminal | The window you type into (also called a console or emulator) |
| Shell | The program that reads your commands and runs them (usually bash) |
| Prompt | The symbol (often $) that shows the shell is ready for input |
| Command | An instruction like ls or cd β a program plus options and arguments |
| Argument | What the command operates on β e.g. a filename (ls Desktop) |
| Option (flag) | Arguments starting with - that tweak behavior β e.g. ls -l means "detailed" |
| Working directory | The folder you are "in" right now β where commands run by default |
A typical command looks like this: ls -l /home/me β
command ls, option -l, argument
/home/me.
Think of the filesystem as a giant tree of folders. Your first job is learning to move around it.
# Where am I? (current working directory) $ pwd /home/me # What's in here? $ ls Desktop Documents Downloads projects # Detailed listing (type, permissions, size, date) $ ls -l # -rw-r--r-- 1 me me 512 Jun 8 10:00 notes.txt # Show hidden files too (those starting with a dot) $ ls -a # Change directory $ cd projects # Go up one level $ cd .. # Straight to your home directory from anywhere $ cd ~
pwd is your GPS showing where you are. ls is looking at the
buildings around you. cd is stepping into a building. cd .. steps back out onto the street.
~ (the tilde) is your home β a shortcut straight back to your house.
Create, copy, move, and delete β every command here maps to something you'd do in a file manager.
# Create an empty file $ touch notes.txt # Create a directory $ mkdir blog # Create directories with parents (-p creates any missing ones) $ mkdir -p blog/2026/posts # Copy a file $ cp notes.txt backup.txt # Copy an entire directory recursively $ cp -r blog blog-copy # Move or rename (mv is both!) $ mv notes.txt blog/ # move into blog $ mv old-name.txt new-name.txt # rename # Delete a file $ rm notes.txt # Delete a directory and everything inside it $ rm -r blog
rm -r deletes a folder and all of its contents permanently. Double-check what you're removing β
there is no "undo".
# Print the whole file $ cat notes.txt # Page through a long file (q to quit) $ less big-file.log # First / last lines $ head -5 config.yml $ tail -10 server.log # Follow a log file as it grows (great for debugging) $ tail -f server.log # Search inside files (grep = text-filter) $ grep ERROR server.log # Count the lines in a file $ wc -l notes.txt
grep is one of the most powerful tools in the Linux kit. It filters lines that match a pattern,
and it composes beautifully with other commands (see pipes below).
Every file has an owner and a set of permissions: read, write, and execute β for the user (u),
the group (g), and everyone else (o). You'll see them in ls -l like this:
# u g o meaning -rwxr-x--- 1 me devs notes.sh # -rwx (me: read+write+execute) r-x (group devs: read+execute) --- (others: nothing) # View permissions $ ls -l notes.sh # Change permissions: u=rwx g=rx o=r β stays -rwxr-xr-- $ chmod u=rwx,g=rx,o=r notes.sh # Short form: 7=rwx, 6=rw, 5=rx, 4=r β u=7 g=5 o=4 = 754 $ chmod 754 notes.sh # Make a script executable $ chmod +x myscript.sh
chmod 754 is read as: 7 for the user, 5 for the group, 4 for everyone else.
Every program you run β including your terminal itself β is a process with an ID (PID).
# List running processes $ ps PID TTY TIME CMD 1234 pts/0 00:00:00 bash # Full view of every process system-wide $ ps aux # Interactive process manager (press q to quit) $ top # The classic process manager $ htop # Kill a process by PID $ kill 1234 # No mercy kill $ kill -9 1234
This is where the CLI stops being a list of tools and becomes a wizard.
The pipe | takes the output of one command and sends it into the next.
# Count how many files are in this folder $ ls | wc -l # Errors in the last 50 lines of a log $ tail -50 server.log | grep ERROR # Find the 5 largest items (disk usage, biggest first) $ du -sh * | sort -hr | head -5 # Redirect output to a file (> overwrites, >> appends) $ echo "hello" > greeting.txt $ date >> greeting.txt
ls dumps raw parts on the belt;
grep inspects them and keeps the good ones; wc counts them at the end.
You bolt as many stages together as you need β that's the pipe |.
When you type commands repeatedly, script them. A script is just a file that runs commands in order.
#!/bin/bash # backup.sh β copy today's logs to an archive folder DATE=$(date +%Y-%m-%d) mkdir -p backups/$DATE cp logs/*.log backups/$DATE/ echo "Backup done at $DATE"
$(...) captures a command's output into a variable. $DATE uses that variable later.
$ vim backup.sh # (any editor works: vim, nano, code)
$ chmod +x backup.sh
$ ./backup.sh
Backup done at 2026-08-08
./ tells the shell "run this file in the current directory".
| Command | What it does |
|---|---|
pwd | Show where you are (current working directory) |
ls, ls -l | List files; -l detailed view |
cd <dir> | Change directory |
mkdir <dir> | Create a directory |
touch <file> | Create an empty file or update its timestamp |
cp <a> <b> | Copy a file (or a folder with -r) |
mv <a> <b> | Move or rename a file |
rm, rm -r | Delete a file / directory + contents |
cat, less | Print a file / browse it page-by-page |
head, tail | Show the first / last lines |
grep <pattern> | Search for matching lines in a file |
chmod | Change file permissions |
ps, top, kill | Inspect / kill processes |
| and > | Pipe between commands / redirect to file |
man command and --help are built-in docs for anything.
history, or Ctrl+R to search it.
alias ll='ls -l' turns short-cut commands into everyday tools.
ssh, find, sed/awk, and (obviously) Docker.
The terminal turns small tools into superpowers β each one simple, and infinitely combinable.
Learn the basics, and the "scary black box" becomes your fastest tool.
Created by jcmatira