Linux Cheat Sheet & Useful Commands
A practical Linux quick-reference handbook designed for everyday terminal usage, troubleshooting, debugging, server administration, development, and DevOps workflows.
Difficulty: Beginner → Advanced
Estimated reading time: Infinite
Introduction
This chapter is intentionally different from the previous ones.
The earlier chapters focused heavily on:
- Linux concepts
- system internals
- workflows
- networking
- automation
- DevOps mindset
This page is designed as:
A practical Linux command handbook.
The goal is not to memorize every command.
Instead, this chapter should become something you regularly return to while:
- debugging servers
- managing infrastructure
- working in the terminal
- deploying applications
- troubleshooting containers
- automating workflows
Over time, many of these commands become muscle memory.
But even experienced Linux engineers constantly look things up.
That is completely normal.
Terminal Navigation
pwd
Displays the current working directory.
pwd
Example output:
/home/john/projects/app
This command is useful when you become lost in deeply nested directories.
Common Use Cases
- verifying current location
- scripting
- debugging terminal workflows
Optional: Why This Matters
Linux systems often contain enormous directory structures.
Understanding where you currently are inside the filesystem is extremely important.
Especially when running dangerous commands like:
rm -rf
ls
Lists files and directories.
ls
Example:
app
docker-compose.yml
README.md
Useful Variants
Detailed List
ls -l
Show Hidden Files
ls -a
Human Readable Sizes
ls -lh
Combined Version
ls -lah
One of the most commonly used Linux commands.
Optional: Understanding Hidden Files
Files beginning with:
.
are hidden files.
Examples:
.gitignore
.env
.bashrc
These are heavily used for:
- configuration
- development environments
- Linux customization
cd
Changes directories.
cd /var/log
Common Navigation Examples
Go Back One Directory
cd ..
Go Home
cd ~
Go to Previous Directory
cd -
Very useful during rapid navigation.
Optional: Linux Navigation Philosophy
Linux workflows heavily rely on fast terminal navigation.
Experienced engineers move through systems extremely quickly using only keyboard navigation.
File Management
touch
Creates an empty file.
touch notes.txt
Common Use Cases
- creating placeholder files
- testing permissions
- creating logs
- scripting
Optional: Interesting Behavior
If the file already exists:
touch
updates its timestamp instead.
mkdir
Creates directories.
mkdir project
Create Nested Directories
mkdir -p app/logs/nginx
Without -p, parent directories must already exist.
Optional: Why Nested Directories Matter
Infrastructure projects often contain deeply structured directories for:
- logs
- configs
- containers
- environments
- deployments
cp
Copies files and directories.
cp file.txt backup.txt
Copy Entire Directory
cp -r project backup-project
The -r flag means:
recursive
Common Beginner Mistake
Forgetting -r when copying directories.
Linux will refuse to copy folders recursively without it.
mv
Moves or renames files.
mv old.txt new.txt
Move File to Another Directory
mv app.log /var/log/app.log
Optional: Why mv Is Powerful
Unlike copy operations:
mv
usually does not duplicate file contents on the same filesystem.
This makes moving files extremely efficient.
rm
Deletes files and directories.
rm file.txt
Remove Directory Recursively
rm -rf project
Flags:
| Flag | Meaning |
|---|---|
-r |
Recursive |
-f |
Force |
Common Beginner Mistake
Running dangerous commands from the wrong directory.
Always verify location first:
pwd
Optional: Why rm Is Dangerous
Unlike graphical operating systems:
Linux usually does not have a recycle bin for terminal deletions.
Deleted files may become unrecoverable.
Viewing Files
cat
Displays file contents.
cat file.txt
Common Use Cases
- viewing configs
- checking logs
- testing files
Optional: Why cat Is Limited
Large files become difficult to read with:
cat
Better alternatives:
- less
- tail
- head
less
Opens files in a scrollable viewer.
less app.log
Useful Shortcuts
| Key | Action |
|---|---|
q |
Quit |
/ |
Search |
n |
Next match |
Why less Is Extremely Important
Large logs may contain millions of lines.
Using:
cat huge.log
can overwhelm the terminal.
tail
Displays the end of files.
tail app.log
Very useful for logs.
Follow Logs Live
tail -f app.log
This continuously watches new log entries.
Common Use Cases
- deployments
- debugging
- monitoring
- production incidents
Optional: Why tail -f Is So Popular
Many Linux workflows revolve around observing systems in real time.
Watching logs live allows engineers to immediately see:
- errors
- crashes
- requests
- service behavior
Searching & Filtering
grep
Searches text patterns.
grep ERROR app.log
Case Insensitive Search
grep -i error app.log
Recursive Search
grep -r "DATABASE_URL" .
Very useful for searching projects and configs.
Common Use Cases
- finding errors
- debugging logs
- searching codebases
- locating configuration values
Optional: Why grep Is One of the Most Important Linux Tools
Infrastructure debugging often means:
finding information quickly.
grep is one of the most heavily used commands in DevOps and server administration.
find
Searches for files and directories.
find / -name "*.log"
Find Large Files
find / -type f -size +1G
Very useful during storage debugging.
Optional: Why find Matters
Linux systems can contain millions of files.
Efficient searching becomes extremely important in production environments.
Permissions
chmod
Changes file permissions.
chmod 755 script.sh
Common Permission Values
| Value | Meaning |
|---|---|
| 755 | Owner full access |
| 644 | Standard file |
| 600 | Private file |
Common Use Cases
- executable scripts
- SSH keys
- web server permissions
Optional: Why Permissions Matter
Linux security heavily relies on filesystem permissions.
Incorrect permissions can cause:
- application failures
- security vulnerabilities
- deployment issues
chown
Changes file ownership.
chown user:user file.txt
Recursive Ownership Change
chown -R www-data:www-data /var/www
Common Real-World Scenario
Web servers often fail because they cannot access files due to ownership problems.
Process Management
ps aux
Displays running processes.
ps aux
Search Processes
ps aux | grep nginx
Understanding Important Columns
| Column | Meaning |
|---|---|
| USER | Process owner |
| PID | Process ID |
| %CPU | CPU usage |
| %MEM | Memory usage |
Optional: Why Processes Matter
Everything running on Linux is a process.
Understanding processes is foundational for:
- DevOps
- containers
- monitoring
- troubleshooting
htop
Interactive process viewer.
htop
Much more user-friendly than:
top
Common Use Cases
- finding resource spikes
- identifying runaway processes
- debugging performance problems
Optional: Production Tip
One of the first things engineers check during incidents:
htop
because CPU or memory exhaustion is extremely common.
kill
Stops processes.
kill PID
Force Kill
kill -9 PID
Common Beginner Mistake
Using:
kill -9
too aggressively.
This forcefully terminates processes without graceful shutdown.
Optional: Understanding Signals
kill actually sends signals to processes.
Examples:
| Signal | Meaning |
|---|---|
| SIGTERM | Graceful stop |
| SIGKILL | Immediate kill |
systemd & Services
systemctl status
Checks service status.
systemctl status nginx
Common Use Cases
- checking failures
- verifying startup
- debugging services
Optional: Why systemd Matters
Most modern Linux distributions use:
systemd
for managing services and system initialization.
Restart Service
systemctl restart nginx
Reload Service
systemctl reload nginx
Reload is often safer because it avoids full downtime.
journalctl
Views system logs.
journalctl -u nginx
Follow Logs Live
journalctl -u nginx -f
One of the most useful production debugging commands.
Optional: Why Logs Matter So Much
Logs tell the story of system behavior.
Many Linux issues become obvious once logs are inspected carefully.
Networking
ip a
Displays network interfaces and IP addresses.
ip a
Common Use Cases
- checking server IPs
- debugging networking
- verifying interfaces
Optional: Why Networking Matters
Modern infrastructure is heavily network-oriented.
Many production problems involve:
- DNS
- firewalls
- ports
- routing
- connectivity
ss -tulnp
Displays listening ports and active sockets.
ss -tulnp
Check Specific Port
ss -tulnp | grep :80
Useful when services fail to start because ports are already occupied.
Optional: Extremely Common Debugging Workflow
Application fails to start.
Why?
Possible cause:
Another process already uses the port.
This command immediately reveals the problem.
curl
Makes HTTP requests.
curl https://example.com
Common Use Cases
- API testing
- debugging services
- checking websites
- monitoring
Optional: Why curl Is So Important
Many infrastructure workflows revolve around HTTP APIs.
curl allows engineers to test systems directly from the terminal.
Disk & Storage
df -h
Displays filesystem disk usage in a human-readable format.
df -h
Common Real-World Scenario
Applications suddenly fail because disk space is exhausted.
This command is one of the first checks during incidents.
Optional: Why Full Disks Are Dangerous
Full disks can cause:
- failed deployments
- logging failures
- database crashes
- Docker issues
- system instability
du -sh *
Shows directory sizes.
du -sh *
Sort by Size
du -sh * | sort -h
Very useful for finding large folders.
Optional: Difference Between df and du
| Command | Purpose |
|---|---|
df |
Entire filesystem usage |
du |
Specific folder usage |
SSH & Remote Access
ssh
Connects to remote systems securely.
ssh user@server
SSH with Key
ssh -i ~/.ssh/key.pem user@server
Common Use Cases
- remote administration
- deployments
- server debugging
- infrastructure management
Optional: Why SSH Is Essential
Most Linux servers are managed remotely.
SSH became one of the foundational technologies of modern infrastructure.
rsync
Synchronizes files efficiently.
rsync -av project/ server:/opt/project
Why rsync Is Popular
Unlike normal copying:
rsync
transfers only changed data.
This makes deployments and backups much faster.
Environment Variables
env
Displays environment variables.
env
Show PATH Variable
echo $PATH
export
Creates environment variables.
export APP_ENV=production
Common Use Cases
- configuration
- secrets
- runtime behavior
- application environments
Temporary Environment Variables
Sometimes you want to run a command with a variable that exists only during that execution.
Example:
APP_ENV=production node app.js
This temporarily creates:
APP_ENV
and immediately runs:
node app.js
The variable disappears after the process exits.
Why This Is Extremely Common
Temporary variables are heavily used in:
- Docker
- CI/CD
- deployments
- testing
- scripting
Docker Essentials
docker ps
Lists running containers.
docker ps
Show All Containers
docker ps -a
docker logs
Displays container logs.
docker logs container
Follow Logs Live
docker logs -f container
Optional: Why Container Logs Matter
Containers often log directly to:
stdout/stderr
Understanding logs is essential for container debugging.
docker exec
Runs commands inside containers.
docker exec -it container bash
Common Use Cases
- debugging containers
- inspecting files
- testing networking
- checking processes
Useful One-Liners
Top Memory Usage Processes
ps aux --sort=-%mem | head
Very useful during performance incidents.
Top CPU Usage Processes
ps aux --sort=-%cpu | head
Find Largest Files
find / -type f -exec du -h {} + | sort -rh | head
Extremely useful during storage emergencies.
Watch Command Continuously
watch -n 1 docker ps
Repeats command every second.
Very useful during deployments and monitoring.
Emergency Recovery Commands
Reboot System
reboot
Shutdown Immediately
shutdown now
View Boot Logs
journalctl -b
Useful after failed boots or crashes.
Remount Filesystem as Read/Write
mount -o remount,rw /
Useful in recovery environments.
Final Thoughts
Linux mastery is not about memorizing commands.
It comes from:
- using systems
- debugging problems
- automating workflows
- understanding infrastructure
- staying curious
Over time, the Linux terminal stops feeling like:
A list of commands
and starts feeling like:
A powerful interface for understanding and controlling systems.