🐧 Learn the Linux CLI

A beginner-friendly guide to navigating the terminal, managing files, controlling processes, and writing shell scripts

1. What is the Linux CLI?

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.

πŸš— Analogy β€” Manual vs Automatic Transmission
A GUI is like an automatic car: everyone can drive it, but you don't really know what's happening under the hood. The command line is like a manual transmission: more to learn at first, but you get full control over every gear. Experienced developers and sysadmins use it because it's faster, scriptable, and works everywhere β€” including on servers that have no screen at all.

🎯 Real-World Examples

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

2. Why learn the CLI? (The Benefits)

⚑ Speed
Batch operations and one-liners do in seconds what takes minutes by hand.
πŸ” Automation
Chain commands with pipes and scripts β€” no more repetitive manual work.
🌍 Works everywhere
Linux, macOS, Windows (WSL/Git Bash), and every cloud server. One set of skills.
πŸ” Precision
Combine tools to filter, transform, and inspect data exactly how you want.
πŸ•ŠοΈ Lightweight
No heavy GUI overhead β€” often the only way to manage remote or headless machines.
πŸ“œ Power & control
Access every part of the system, understand how it works, and script it your way.

3. First Things First β€” the Shell and the Prompt

🧠 Key Ideas

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.

4. Navigating the Filesystem

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 ~
πŸ—ΊοΈ Analogy β€” Driving Around a City
The filesystem is a city. 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.

5. Managing Files & Directories

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
πŸ—‘οΈ Caution: Linux has no recycling bin for the terminal. rm -r deletes a folder and all of its contents permanently. Double-check what you're removing β€” there is no "undo".

6. Reading & Searching File Contents

# 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).

7. Permissions

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.

8. Processes & System Tools

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

9. Pipes, Redirects & Combining Commands

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
🏭 Analogy: Assembly Line
A pipeline is a factory assembly line. 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 |.

10. Your First Shell Script

When you type commands repeatedly, script them. A script is just a file that runs commands in order.

πŸ“œ A tiny backup script

#!/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.

Create the script file
$ vim backup.sh
# (any editor works: vim, nano, code)
Make it executable
$ chmod +x backup.sh
Run it
$ ./backup.sh
Backup done at 2026-08-08

./ tells the shell "run this file in the current directory".

11. Quick Reference β€” Common Commands

CommandWhat it does
pwdShow where you are (current working directory)
ls, ls -lList 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 -rDelete a file / directory + contents
cat, lessPrint a file / browse it page-by-page
head, tailShow the first / last lines
grep <pattern>Search for matching lines in a file
chmodChange file permissions
ps, top, killInspect / kill processes
| and >Pipe between commands / redirect to file

12. Best Practices & Next Steps

πŸ›‘οΈ Read before you run
Understand a command before executing it β€” never blindly paste from the internet.
πŸ“š Check the man page
man command and --help are built-in docs for anything.
↩️ Use your history
Arrow up to repeat commands; history, or Ctrl+R to search it.
⚑ Embrace tab completion
Tab completes file names and commands β€” it's a massive speed booster.
πŸ”‘ Make aliases
alias ll='ls -l' turns short-cut commands into everyday tools.
πŸ“ˆ Keep learning
Next topics: 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