By the end of this tutorial you’ll be able to:
- Navigate any Linux filesystem like a pro
- Create, move, copy, delete files/folders with confidence
- Master permissions (chmod, chown, sudo)
- Pipe commands like a wizard (grep, awk, sed, cut)
- Write your first bash scripts
- Automate boring stuff forever
1. Why Learn the Command Line?
- GUIs lie to you – the terminal never does
- 99% of servers have no GUI
- You’ll be 10× faster once you stop clicking
First command ever:
bash
pwd # "Where am I?" → /home/tim
2. The Filesystem Hierarchy
text
/ → root (everything lives here)
├── bin essential commands
├── etc configuration files
├── home your personal folder
├── var logs, databases
├── tmp temporary files
└── usr user programs
3. Navigation Masterclass
bash
ls # list ls -la # show hidden files + permissions cd Documents # change directory cd .. # go up one level cd ~ # go home cd / # go to root cd - # go back to previous folder
Absolute vs Relative paths
cd /etc/ssl # absolute (always starts with /)
cd ../config # relative (from where you are)
4. Creating & Deleting Stuff
bash
touch newfile.txt
mkdir my_folder
mkdir -p parent/child/grandchild # creates all missing folders
cp file.txt backup.txt
cp -r folder/ backup_folder/
mv old.txt new.txt
mv file.txt /tmp/ # move + rename in one go
rm file.txt
rm -r dangerous_folder/
rm -rf / # ← don't laugh, this is how legends are born
5. Viewing & Editing Files
cat file.txt
less huge.log # scroll with arrow keys, q to quit
head -n 5 file.txt # first 5 lines
tail -n 10 log.txt # last 10 lines (perfect for logs)
Editors
bash
nano simple.txt # beginner-friendly
vim expert.txt # (Tim shows how to escape :q!)
6. Permissions – The Matrix of Linux
Every file has 3 groups: owner | group | others Each can have: r (read) | w (write) | x (execute)
bash
ls -l
# -rwxr-xr-- 1 tim staff 1234 Oct 25 12:00 script.sh
Octal notation cheat-sheet
bash
chmod 644 file.txt # owner: rw, everyone else: r
chmod 755 script.sh # owner: rwx, everyone else: rx
chmod 700 secret/ # only you
Change owner
bash
sudo chown tim:admin important.txt
7. Finding Anything, Anywhere
bash
find / -name "*.conf" 2>/dev/null # search whole system
find . -type f -size +100M # huge files in current folder
find . -mtime -7 # modified in last 7 days
# Lightning-fast alternative
locate nginx.conf
# (first run: sudo updatedb)
8. grep – Your Text Mining Superpower
bash
grep "error" log.txt
grep -i "login" access.log # case-insensitive
grep -r "TODO" . # recursive in current folder
grep -n "crash" *.py # show line numbers
grep -v "debug" production.log # exclude lines
Real-world one-liners
bash
# Last 100 lines that contain "Failed password"
tail -n 100 /var/log/auth.log | grep "Failed password"
# Count 404 errors in Nginx log
grep " 404 " access.log | wc -l
9. Pipes & Redirection – Where the Magic Happens
bash
# > overwrite >> append
echo "Hello" > file.txt
cat *.log >> combined.log
# Pipe = send output of left command as input to right
ps aux | grep python
cat access.log | grep "POST" | grep "api" > posts.log
Ultimate log analyzer in one line
bash
cat error.log | cut -d' ' -f1 | sort | uniq -c | sort -nr | head -10
# → Top 10 IP addresses causing errors
10. awk, sed, cut – Text Processing Gods
bash
# Print 9th column of ls -l
ls -l | awk '{print $9}'
# Replace all "old" with "new"
sed 's/old/new/g' file.txt
# Extract first 20 characters of every line
cut -c 1-20 huge.txt
Live demo: parse Apache log
bash
awk '{print $1 " → " $7}' access.log | head -5
# 192.168.1.1 → /index.html
11. Bash Scripting – Automate Your Life
Your first script backup.sh
bash
#!/bin/bash
# backup.sh – daily backup script
SOURCE="/home/tim/Documents"
DEST="/backup/$(date +%Y-%m-%d)"
mkdir -p "$DEST"
cp -r "$SOURCE" "$DEST"
echo "Backup completed: $DEST"
Make it executable & run daily:
bash
chmod +x backup.sh
crontab -e
# Add this line:
0 2 * * * /home/tim/backup.sh >> /var/log/backup.log 2>&1
Final Cheat Sheet
bash
# Navigation
cd ~; pwd; ls -la
# File ops
touch file; mkdir -p a/b/c; cp -r src dest; mv old new; rm -rf dir
# Viewing
cat f; less huge; head -n 5; tail -f log
# Search
grep -r "word" .; find . -name "*.py"
# Permissions
chmod 755 script.sh; sudo chown user:group file
# One-liners everyone should know
history | grep ssh
df -h # disk space
du -sh * | sort -hr # folder sizes
htop # (install if missing)
# Bonus: Download YouTube video in terminal
yt-dlp "https://youtu.be/avg65oY7sj4"