Linux Cheatsheet
Linux Cheatsheet
This comprehensive cheatsheet provides essential Linux commands organized by category for quick reference.
Commands Reference
System Information
Memory & Processes
free # Display memory usage
free -h # Human-readable memory usage
ps # List current processes
ps aux # Detailed process list
top # Interactive process viewer
htop # Enhanced process viewer
System Details
uptime # System uptime and load
w # Who is logged in
uname -a # System information
hostname # Display hostname
lshw # Hardware configuration
history # Command history
tty # Terminal device info
Documentation
man [command] # Manual pages
info [command] # Software documentation
help [command] # Built-in help
whatis [command] # Brief description
File and Directory Management
Navigation
pwd # Print working directory
cd [dir] # Change directory
cd .. # Go to parent directory
cd ~ # Go to home directory
cd - # Go to previous directory
Listing Files
ls # List files
ls -l # Long format
ls -a # Show hidden files
ls -la # Long format with hidden
ls -R # Recursive listing
ls -h # Human-readable sizes
File Operations
touch [file] # Create/update file
cp [src] [dest] # Copy file
cp -r [src] [dest] # Copy directory
mv [src] [dest] # Move/rename
rm [file] # Remove file
rm -r [dir] # Remove directory
rm -f [file] # Force remove
rm -rf [dir] # Force remove directory
Directory Operations
mkdir [dir] # Create directory
mkdir -p [path] # Create nested directories
rmdir [dir] # Remove empty directory
File Permissions
chmod 755 [file] # Change permissions
chmod +x [file] # Make executable
chown user [file] # Change owner
chgrp group [file] # Change group
File Information
file [file] # Determine file type
stat [file] # File statistics
lsof # List open files
Text Processing
Viewing Files
cat [file] # Display entire file
head [file] # Display first 10 lines
head -n 20 [file] # Display first 20 lines
tail [file] # Display last 10 lines
tail -f [file] # Follow file updates
less [file] # Page through file
more [file] # Page through file
Text Manipulation
grep [pattern] [file] # Search for pattern
grep -i [pattern] [file] # Case-insensitive search
grep -r [pattern] [dir] # Recursive search
grep -n [pattern] [file] # Show line numbers
egrep [pattern] [file] # Extended regex
Text Processing Tools
sort [file] # Sort lines
sort -n [file] # Numerical sort
uniq [file] # Remove duplicates
cut -d: -f1 [file] # Extract fields
wc [file] # Word/line count
wc -l [file] # Line count only
sed 's/old/new/g' [file] # Find and replace
tr 'a-z' 'A-Z' # Translate characters
Text Editors
nano [file] # Simple editor
vi [file] # Vi editor
vim [file] # Vi improved
Process Management
Process Control
ps # List processes
ps aux # Detailed process list
top # Interactive process monitor
htop # Enhanced process monitor
kill [PID] # Terminate process
kill -9 [PID] # Force kill process
killall [name] # Kill by process name
Background Jobs
command & # Run in background
jobs # List background jobs
fg %1 # Bring job to foreground
bg %1 # Send job to background
nohup command & # Run immune to hangups
System Administration
User Management
sudo command # Run as superuser
sudo -s # Root shell
su [user] # Switch user
sudo -u [user] command # Run as specific user
passwd # Change password
whoami # Current username
who # Logged in users
id # User and group info
User Account Management
useradd [user] # Add user
adduser [user] # Interactive user creation
usermod -aG [group] [user] # Add user to group
userdel [user] # Delete user
groupadd [group] # Create group
Package Management (APT)
sudo apt update # Update package list
sudo apt upgrade # Upgrade packages
sudo apt install [pkg] # Install package
sudo apt remove [pkg] # Remove package
sudo apt purge [pkg] # Remove with config
sudo apt autoremove # Remove unused
apt search [term] # Search packages
dpkg -l # List installed packages
Service Management
systemctl status [service] # Service status
systemctl start [service] # Start service
systemctl stop [service] # Stop service
systemctl restart [service] # Restart service
systemctl enable [service] # Enable at boot
systemctl disable [service] # Disable at boot
System Control
shutdown -h now # Shutdown immediately
shutdown -r now # Restart immediately
reboot # Restart system
halt # Halt system
sync # Write buffers to disk
Network Management
Network Configuration
ip addr # Show IP addresses
ip link # Show network interfaces
ifconfig # Interface configuration
ping [host] # Test connectivity
ping -c 4 [host] # Ping 4 times
Network Tools
ssh user@host # SSH connection
scp [file] user@host:[path] # Secure copy
wget [url] # Download file
curl [url] # Transfer data
netstat -tulpn # Network connections
ss -tulpn # Socket statistics
Wireless
iwconfig # Wireless configuration
iwlist scan # Scan for networks
Firewall (UFW)
sudo ufw enable # Enable firewall
sudo ufw disable # Disable firewall
sudo ufw status # Firewall status
sudo ufw allow [port] # Allow port
sudo ufw deny [port] # Deny port
sudo ufw allow from [ip] # Allow IP
File Compression & Archives
Creating Archives
tar -cvf archive.tar [files] # Create tar
tar -czvf archive.tar.gz [files] # Create tar.gz
tar -cjvf archive.tar.bz2 [files] # Create tar.bz2
zip archive.zip [files] # Create zip
Extracting Archives
tar -xvf archive.tar # Extract tar
tar -xzvf archive.tar.gz # Extract tar.gz
tar -xjvf archive.tar.bz2 # Extract tar.bz2
unzip archive.zip # Extract zip
Compression
gzip [file] # Compress with gzip
gunzip [file.gz] # Decompress gzip
bzip2 [file] # Compress with bzip2
bunzip2 [file.bz2] # Decompress bzip2
Disk Management
Disk Usage
df -h # Disk space usage
du -h # Directory space usage
du -sh [dir] # Total directory size
du -h --max-depth=1 # Size of subdirectories
Disk Operations
mount # Show mounted filesystems
mount [device] [dir] # Mount device
umount [dir] # Unmount
fdisk -l # List disk partitions
lsblk # List block devices
Environment & Shell
Variables
echo $VAR # Display variable
export VAR=value # Set environment variable
env # Show all variables
unset VAR # Remove variable
alias ll='ls -la' # Create alias
unalias ll # Remove alias
Shell Control
bash # Start new bash shell
exit # Exit shell
clear # Clear screen
source [file] # Execute script in current shell
. [file] # Same as source
Terminal Shortcuts
Navigation
Ctrl+A- Beginning of lineCtrl+E- End of lineCtrl+U- Delete to beginningCtrl+K- Delete to endCtrl+W- Delete wordAlt+F- Forward one wordAlt+B- Back one word
Process Control
Ctrl+C- Interrupt processCtrl+D- End of input/ExitCtrl+Z- Suspend processCtrl+L- Clear screen
History
Ctrl+R- Search historyCtrl+P/↑- Previous commandCtrl+N/↓- Next command!!- Repeat last command!$- Last argument of previous command
Copy/Paste
Ctrl+Shift+C- CopyCtrl+Shift+V- Paste
Tab Management
Ctrl+Shift+T- New tabCtrl+Shift+W- Close tabCtrl+PageUp/PageDown- Switch tabs
Advanced Tools
System Monitoring
vmstat # Virtual memory stats
iostat # I/O statistics
dmesg # Kernel messages
journalctl # System logs
File Search
find [dir] -name [pattern] # Find by name
find [dir] -type f -size +1M # Find large files
locate [file] # Find in database
updatedb # Update locate database
which [command] # Command location
whereis [command] # Binary, source, manual
Text Processing
awk '{print $1}' [file] # Print first column
paste [file1] [file2] # Merge files
split -l 100 [file] # Split by lines
diff [file1] [file2] # Compare files
comm [file1] [file2] # Compare sorted files
Scheduling
crontab -e # Edit cron jobs
crontab -l # List cron jobs
at 10:00 # Schedule one-time job
atq # List scheduled jobs
Miscellaneous
date # Current date/time
cal # Calendar
bc # Calculator
time [command] # Time command execution
watch [command] # Run command repeatedly
tree # Directory tree
neofetch # System info with ASCII art
Tips & Best Practices
- Tab Completion: Press
Tabto auto-complete commands and paths - Command History: Use
history | grep [term]to search command history - Pipes: Chain commands with
|(e.g.,ls -la | grep txt) - Redirection: Use
>to redirect output,>>to append - Background Jobs: Add
&to run commands in background - Wildcards: Use
*for multiple characters,?for single character - Command Substitution: Use
$(command)or`command` - Check Before Delete: Always use
lsbeforermwith wildcards
Common Command Combinations
# Find and delete files older than 30 days
find /path -type f -mtime +30 -delete
# Monitor log file in real-time
tail -f /var/log/syslog | grep ERROR
# Find largest files
du -ah / 2>/dev/null | sort -rh | head -20
# Backup directory
tar -czvf backup-$(date +%Y%m%d).tar.gz /path/to/dir
# Search and replace in multiple files
find . -type f -name "*.txt" -exec sed -i 's/old/new/g' {} \;
# System resource usage
ps aux --sort=-%cpu | head -10 # Top CPU users
ps aux --sort=-%mem | head -10 # Top memory users
Linux Video Tutorials
Learn Linux through these carefully selected video tutorials, organized by difficulty level and topic.
🎯 Quick Navigation
Complete Beginner Courses
The 50 Most Popular Linux & Terminal Commands
By FreeCodeCamp.org | 5 Hours | 1.4M+ Views
Perfect for absolute beginners. Learn the 50 most essential Linux commands with clear explanations and practical examples.
What you'll learn:
- Essential file and directory commands
- Text processing and manipulation
- System monitoring and management
- Network and permission commands
- Shell scripting basics
Linux Operating System - Crash Course for Beginners
By FreeCodeCamp.org | 3 Hours
A comprehensive introduction to Linux, perfect for those new to the operating system.
Topics covered:
- Installing Linux (Virtual Machine setup)
- Desktop environment navigation
- File system structure
- Package management
- Basic system administration
Command Line Mastery
Linux Tutorial for Beginners - Learn Linux in 60 Minutes
Quick start guide for busy learners
Perfect for:
- Quick overview of Linux basics
- Refresher for returning users
- Pre-interview preparation
Bash Scripting Tutorial for Beginners
Learn shell scripting from scratch
You'll master:
- Writing your first bash script
- Variables and conditionals
- Loops and functions
- Automation basics
System Administration
Linux System Administration Full Course
Comprehensive sysadmin training
Professional skills covered:
- User and group management
- Service configuration
- Security hardening
- Performance monitoring
- Backup strategies
Recommended Channels
🎥 NetworkChuck
Focus: Networking & Security
- Engaging, high-energy tutorials
- Linux for hackers series
- Real-world scenarios
📺 The Linux Experiment
Focus: Desktop Linux
- Distribution reviews
- Linux news weekly
- Privacy and security tips
🖥️ Learn Linux TV
Focus: In-depth tutorials
- Server administration
- Docker and containers
- Enterprise Linux topics
🎯 DistroTube
Focus: Power users
- Window manager tutorials
- Command line tools
- Customization guides
Learning Tips
📚 Effective Learning Strategy
- Start with Basics
- Watch the FreeCodeCamp 50 commands video first
- Practice each command as you learn
- Don't skip the fundamentals
- Set Up Practice Environment
- Use VirtualBox or VMware
- Try multiple distributions
- Break things and fix them!
- Follow Along Actively
- Pause videos frequently
- Type every command yourself
- Experiment with variations
- Build Projects
- Automate daily tasks
- Create backup scripts
- Set up a home server
- Join Communities
- r/linux4noobs - Beginner-friendly
- Linux Questions - Expert help
- Ask Ubuntu - Ubuntu specific
🎯 Recommended Learning Path
graph LR
A[Basic Commands] --> B[File System]
B --> C[Text Processing]
C --> D[Shell Scripting]
D --> E[System Admin]
E --> F[Advanced Topics]
Week 1-2: Basic commands and navigation
Week 3-4: File management and permissions
Week 5-6: Text processing and pipes
Week 7-8: Basic shell scripting
Week 9-10: System administration basics
Week 11-12: Choose specialization (Security/DevOps/SysAdmin)
🚀 Quick Reference Playlists
- Linux Basics Playlist - Start here
- Command Line Power User - Level up
- Linux Security Essentials - Stay safe
💡 Pro Tips
- Speed Control: Use YouTube's playback speed (1.25x or 1.5x) for efficiency
- Subtitles: Enable for better retention
- Timestamps: Check video descriptions for quick navigation
- Downloads: Save videos offline for reference
- Notes: Keep a command journal as you learn