Linux command line mastery is essential for system administrators and developers. This comprehensive Linux cheat sheet covers 200+ essential commands for file operations, process management, user administration, permissions, networking, and system troubleshooting. From basics to advanced administration.
Quick Navigation: Files | Text | System | Users | Search | Archive
File Operations
Navigation & Listing
pwd # Print working directory
ls -lah # List all files with permissions and sizes
cd /path/to/dir # Change directory
cd - # Go to previous directory
File Manipulation
cp source dest # Copy file
cp -r source dest # Copy directory recursively
mv source dest # Move/rename file
rm file # Remove file
rm -rf dir # Remove directory recursively (dangerous!)
mkdir -p path/to/dir # Create directory with parents
touch file # Create empty file or update timestamp
File Viewing
cat file # Display entire file
less file # View file with paging
head -n 20 file # Show first 20 lines
tail -n 20 file # Show last 20 lines
tail -f file # Follow file in real-time
Text Processing
Search & Filter
grep pattern file # Search for pattern in file
grep -r pattern dir # Recursive search
grep -i pattern file # Case-insensitive search
grep -v pattern file # Invert match (show non-matching)
awk '{print $1}' file # Print first column
sed 's/old/new/g' file # Replace text
Text Manipulation
cut -d: -f1 /etc/passwd # Extract first field (username)
sort file # Sort lines
sort -u file # Sort and remove duplicates
uniq file # Remove adjacent duplicates
wc -l file # Count lines
tr 'a-z' 'A-Z' < file # Convert to uppercase
System Information
Process Management
ps aux # List all processes
ps aux | grep process_name # Find specific process
top # Real-time process viewer
htop # Better process viewer (if installed)
kill PID # Kill process by ID
kill -9 PID # Force kill process
killall process_name # Kill all processes by name
pgrep process_name # Find process ID by name
System Stats
df -h # Disk space usage
du -sh * # Directory sizes
free -h # Memory usage
uptime # System uptime and load
uname -a # System information
lsb_release -a # Distribution information
Network
ip addr # Show IP addresses
ip link # Show network interfaces
ss -tulpn # Show listening ports
netstat -tulpn # Show listening ports (older)
ping host # Test connectivity
traceroute host # Trace route to host
dig domain # DNS lookup
nslookup domain # DNS lookup (older)
curl -I url # Fetch HTTP headers
wget url # Download file
User & Permissions
User Management
whoami # Current username
id # User ID and groups
sudo -i # Switch to root
su - username # Switch user
w # Who is logged in
last # Login history
Permissions
chmod 755 file # rwxr-xr-x
chmod +x script # Add execute permission
chown user:group file # Change owner
chown -R user:group dir # Change owner recursively
umask 022 # Set default permissions
File Search & Location
find /path -name "*.txt" # Find files by name
find /path -type f -mtime -7 # Files modified in last 7 days
find /path -type f -size +100M # Files larger than 100MB
locate filename # Fast file search (uses database)
updatedb # Update locate database
which command # Find command location
whereis command # Find binary, source, manual
Archiving & Compression
tar -czf archive.tar.gz dir # Create compressed tarball
tar -xzf archive.tar.gz # Extract tarball
tar -tf archive.tar.gz # List tarball contents
zip -r archive.zip dir # Create zip archive
unzip archive.zip # Extract zip
gzip file # Compress file
gunzip file.gz # Decompress file
Disk & Filesystem
mount /dev/sdb1 /mnt # Mount filesystem
umount /mnt # Unmount filesystem
lsblk # List block devices
fdisk -l # List disk partitions
mkfs.ext4 /dev/sdb1 # Format partition as ext4
fsck /dev/sdb1 # Check filesystem
dd if=/dev/zero of=file bs=1M count=100 # Create 100MB file
Package Management
Debian/Ubuntu (apt)
apt update # Update package list
apt upgrade # Upgrade packages
apt install package # Install package
apt remove package # Remove package
apt search keyword # Search packages
apt show package # Show package info
RHEL/CentOS (yum/dnf)
yum update # Update packages
yum install package # Install package
yum remove package # Remove package
yum search keyword # Search packages
dnf install package # DNF (newer) install
System Control
systemctl start service # Start service
systemctl stop service # Stop service
systemctl restart service # Restart service
systemctl status service # Check service status
systemctl enable service # Enable at boot
systemctl disable service # Disable at boot
journalctl -u service # View service logs
journalctl -f # Follow system logs
Useful One-Liners
# Find largest directories
du -h /path | sort -rh | head -10
# Find and delete files older than 30 days
find /path -type f -mtime +30 -delete
# Monitor log file for errors
tail -f /var/log/syslog | grep -i error
# Count files in directory
find /path -type f | wc -l
# Show listening services and their PIDs
ss -tulpn | grep LISTEN
# Find processes using most CPU
ps aux | sort -nrk 3,3 | head -10
# Find processes using most memory
ps aux | sort -nrk 4,4 | head -10
# Quick HTTP server (Python 3)
python3 -m http.server 8000
# Generate random password
openssl rand -base64 32
# Check which process is using a file
lsof /path/to/file
# Find files containing text
grep -rnw '/path' -e 'pattern'
# Sync directories
rsync -avz source/ dest/
# Create SSH tunnel
ssh -L 8080:localhost:80 user@remote
# Monitor bandwidth usage
iftop -i eth0
# Disk usage sorted
df -h | sort -k5 -r
📥 Download & Print
Want a PDF version? This cheat sheet is optimized for printing:
- Use your browser’s Print function (Ctrl/Cmd + P)
- Select “Save as PDF”
- Choose landscape orientation for best results
Stay Updated: Bookmark this page for the latest commands and best practices.
Last Updated: March 8, 2026