Linux Crash Course#
Table of Contents#
- 1. The UNIX Philosophy
- 2. Essential Navigation & File Ops
- 3. Text Inspection & Stream Tools
- 4. Pipelines & I/O Redirection
- 5. Permissions, Ownership & Modes
- 6. Processes, Jobs & Signals
- 7. Users, Groups & Privilege Escalation
- 8. Networking, Ports & SSH
- 9. Package Management
- 10. Bash Scripting Essentials
- 11. Linux Command Cheat Sheet
1. The UNIX Philosophy#
Linux is built on core principles articulated by Doug McIlroy and Ken Thompson:
- Write programs that do one thing and do it well.
- Write programs to work together. Standard input, standard output, and standard error unify tools into composable chains.
- Write programs to handle text streams, because that is a universal interface.
- Everything is a file: Disks, terminals, network sockets, system memory metrics, and hardware devices are all represented as byte streams accessible through standard read/write calls.
2. Essential Navigation & File Ops#
The Linux filesystem is a single inverted tree rooted at /. Key commands:
pwd # Print working directory
cd /var/log # Change to absolute directory
cd ../ # Move up one directory level
cd ~ # Jump to user home directory ($HOME)
ls -la # List all files (including hidden .files) with permissions & sizes
mkdir -p project/src/api # Create directory tree recursively
cp -r src/ dist/ # Copy directory recursively
mv old_name.txt new.txt # Rename or move file
rm -rf temp/ # Forcefully remove directory without prompting (use with care!)
touch app.py # Create empty file or update timestamp
3. Text Inspection & Stream Tools#
Linux includes industrial-grade text processors designed for massive log files and tabular data:
cat file.txt # Print entire file content to stdout
less large_log.log # Interactive pager (search with '/', navigate with 'q', 'g', 'G')
head -n 20 data.csv # View first 20 lines
tail -f /var/log/syslog # Follow live appends to file in real-time
grep -rn "ERROR" ./src # Recursively search for 'ERROR' with line numbers
wc -l access.log # Count total lines in a file
sort -u users.txt # Sort lines alphabetically and deduplicate
4. Pipelines & I/O Redirection#
Every process starts with three default file descriptors:
0: stdin(Standard Input)1: stdout(Standard Output)2: stderr(Standard Error)
# Output redirection
echo "Starting build" > build.log # Overwrite file with stdout
echo "Step completed" >> build.log # Append stdout to file
python app.py 2> error.log # Redirect stderr only
python app.py > output.log 2>&1 # Combine stdout and stderr into one file
python app.py > /dev/null 2>&1 # Discard all output completely
# Pipelines: Connect stdout of left command to stdin of right command
cat access.log | grep " 404 " | awk '{print $7}' | sort | uniq -c | sort -nr | head -n 10
5. Permissions, Ownership & Modes#
Every file and directory tracks 3 sets of permissions: User (Owner), Group, and Others:
r (read) = 4w (write) = 2x (execute) = 1
chmod 755 script.sh # rwxr-xr-x (Owner: read/write/exec, Group/Others: read/exec)
chmod 600 id_rsa # rw------- (Owner: read/write only, Private SSH key requirement)
chmod +x deploy.sh # Add execute permission for everyone
chown ec2-user:www-data site/ # Change owner to ec2-user and group to www-data
chown -R ec2-user:ec2-user . # Recursively change ownership for current directory
6. Processes, Jobs & Signals#
Programs run as OS processes assigned a unique PID. You can inspect, prioritize, and terminate them:
ps aux # Snapshot of all running processes on the system
top # Real-time task manager (press 'q' to exit, 'M' to sort by RAM)
pgrep -l python # Find PIDs matching name 'python'
kill -15 <PID> # SIGTERM: Polite shutdown request (allows cleanup)
kill -9 <PID> # SIGKILL: Immediate hardware termination by kernel (cannot be caught)
# Backgrounding and Job Control
python server.py & # Launch process directly in background
jobs # List background jobs in current shell
fg %1 # Bring job 1 to foreground
# Press Ctrl+Z to pause foreground job, then run:
bg %1 # Resume paused job in background
7. Users, Groups & Privilege Escalation#
Linux is multi-user by design. The superuser root has UID 0 and unlimited access:
whoami # Print current active username
id # Show UID, GID, and supplementary group memberships
sudo command # Execute a single command with root privileges
sudo -i # Open interactive root shell
useradd -m -s /bin/bash devops # Create new user with home directory and default bash shell
passwd devops # Set or update password
usermod -aG sudo devops # Add user to sudoers group (Debian/Ubuntu)
usermod -aG wheel devops # Add user to wheel group (RHEL/Fedora/Amazon Linux)
8. Networking, Ports & SSH#
Inspecting connections, transferring files, and managing remote cloud servers:
ip addr show # Display IP addresses on all network interfaces
ss -tulpn # Show listening TCP/UDP ports and the process using each
curl -I https://example.com # Fetch HTTP response headers
ping -c 4 8.8.8.8 # Test network round-trip latency to Google DNS
# SSH and Remote File Copy
ssh -i key.pem ec2-user@44.193.134.238
scp -i key.pem file.tar.gz ec2-user@remote:/tmp/
rsync -avz -e "ssh -i key.pem" dist/ ec2-user@remote:/var/www/site/
9. Package Management#
Installing software across major Linux distributions:
- Debian / Ubuntu (APT):
sudo apt update && sudo apt install -y nginx htop git - Amazon Linux / RHEL / Fedora (DNF / YUM):
sudo dnf install -y nginx htop git
10. Bash Scripting Essentials#
A production-ready bash automation script template:
#!/usr/bin/env bash
set -euo pipefail # Strict mode: exit immediately on error, unset vars, or pipe failure
APP_NAME="techtoday-worker"
TARGET_DIR="/var/www/${APP_NAME}"
echo "Deploying ${APP_NAME} to ${TARGET_DIR}..."
if [ ! -d "${TARGET_DIR}" ]; then
echo "Directory does not exist. Creating..."
sudo mkdir -p "${TARGET_DIR}"
fi
for file in *.html *.css; do
if [ -f "$file" ]; then
echo "Validating $file..."
fi
done
echo "Deployment successful! Exit code: $?"
11. Linux Command Cheat Sheet#
Top Commands & Mental Models
grep -rn "pattern" .: Search string recursively across codebase with line numbers.find . -name "*.log" -mtime +7 -delete: Clean up log files older than 7 days.tar -czvf archive.tar.gz dir/: Compress folder into gzip tarball.tar -xzvf archive.tar.gz: Extract gzip tarball.df -h: Check disk space consumption across mount points.du -sh * | sort -h: List folders in current directory sorted by disk usage.free -h: Inspect available, used, and cached RAM and swap.
Next Steps: Advance to enterprise Linux administration in the Linux Detailed Course, or review low-level operating system internals in the OS Crash Course. Explore all courses at All OS Courses.