Linux Cheatsheet
Comprehensive Linux command reference with 200+ commands. Search, filter by category, and click to copy.
Navigation
pwdcd [dir]cd ~cd -cd ..pwd - Print working directory
cd - Change directory
cd - Go to home directory
cd - Go to previous directory
cd - Go up one level
Listing
lsls -lls -lals -lhls -lSls -ltls -Rtreetree -L 2ls - List directory contents
ls - Long format listing
ls - Include hidden files
ls - Human-readable sizes
ls - Sort by size
ls - Sort by time
ls - Recursive listing
tree - Directory tree structure
tree - Tree with depth limit
File Operations
cp [src] [dest]cp -r [src] [dest]cp -i [src] [dest]mv [src] [dest]rm [file]rm -r [dir]rm -rf [dir]mkdir [dir]mkdir -p [path]touch [file]ln -s [target] [link]ln [target] [link]cp - Copy file
cp - Copy directory recursively
cp - Copy with confirmation
mv - Move or rename
rm - Remove file
rm - Remove directory
rm - Force remove (dangerous)
mkdir - Create directory
mkdir - Create nested directories
touch - Create empty file
ln - Create symbolic link
ln - Create hard link
Archives
tar -cvf archive.tar [files]tar -xvf archive.tartar -czvf archive.tar.gz [files]tar -xzvf archive.tar.gztar -cjvf archive.tar.bz2 [files]zip -r archive.zip [dir]unzip archive.zipgzip [file]gunzip [file.gz]tar - Create tar archive
tar - Extract tar archive
tar - Create gzipped tar
tar - Extract gzipped tar
tar - Create bz2 tar
zip - Create zip archive
unzip - Extract zip archive
gzip - Compress file
gunzip - Decompress file
Viewing
cat [file]cat -n [file]less [file]more [file]head [file]head -n 20 [file]tail [file]tail -n 20 [file]tail -f [file]cat - Display file contents
cat - Display with line numbers
less - View with paging
more - View with paging (basic)
head - Show first 10 lines
head - Show first 20 lines
tail - Show last 10 lines
tail - Show last 20 lines
tail - Follow file in real-time
Searching
grep [pattern] [file]grep -i [pattern] [file]grep -r [pattern] [dir]grep -n [pattern] [file]grep -v [pattern] [file]grep -c [pattern] [file]grep -l [pattern] [files]grep -E [regex] [file]grep - Search for pattern
grep - Case-insensitive search
grep - Recursive search
grep - Show line numbers
grep - Invert match
grep - Count matches
grep - List matching files
grep - Extended regex
Processing
sort [file]sort -r [file]sort -n [file]sort -u [file]uniq [file]uniq -c [file]wc [file]wc -l [file]cut -d',' -f1 [file]tr 'a-z' 'A-Z'sed 's/old/new/g' [file]awk '{print $1}' [file]diff [file1] [file2]sort - Sort lines
sort - Reverse sort
sort - Numeric sort
sort - Sort and unique
uniq - Remove duplicates
uniq - Count occurrences
wc - Count lines, words, chars
wc - Count lines only
cut - Extract field
tr - Translate characters
sed - Replace text
awk - Print first column
diff - Compare files
Viewing Processes
psps auxps -efps aux | grep [name]tophtoppgrep [name]pidof [name]ps - Show current processes
ps - Show all processes
ps - Full format listing
ps - Find process by name
top - Real-time process viewer
htop - Interactive process viewer
pgrep - Get PID by name
pidof - Get PID of program
Managing Processes
kill [pid]kill -9 [pid]killall [name]pkill [pattern]bgfgjobs[command] &nohup [command] &nice -n 10 [command]renice -n 10 [pid]kill - Terminate process
kill - Force kill process
killall - Kill by name
pkill - Kill by pattern
bg - Resume in background
fg - Bring to foreground
jobs - List background jobs
[command] - Run in background
nohup - Run immune to hangups
nice - Run with priority
renice - Change priority
System Info
uname -auname -rhostnameuptimedatecalwhoamiidlastwlscpulsblklsusblspcidmesg | tailuname - System information
uname - Kernel version
hostname - Show hostname
uptime - System uptime
date - Current date/time
cal - Show calendar
whoami - Current username
id - User and group IDs
last - Last logged in users
w - Who is logged in
lscpu - CPU information
lsblk - Block devices
lsusb - USB devices
lspci - PCI devices
dmesg - Kernel messages
Disk Usage
df -hdf -idu -sh [dir]du -sh *du -sh * | sort -hrncdufdisk -lmountmount [device] [dir]umount [dir]df - Disk space usage
df - Inode usage
du - Directory size
du - Size of each item
du - Sorted by size
ncdu - Interactive disk usage
fdisk - List partitions
mount - Show mounted filesystems
mount - Mount filesystem
umount - Unmount filesystem
Memory
free -hfree -mvmstatcat /proc/meminfofree - Memory usage
free - Memory in MB
vmstat - Virtual memory stats
cat - Detailed memory info
Network Info
ip aip linkifconfighostname -Icat /etc/resolv.confcat /etc/hostsip - Show IP addresses
ip - Show interfaces
ifconfig - Network config (legacy)
hostname - Show local IPs
cat - DNS servers
cat - Hosts file
Connectivity
ping [host]ping -c 4 [host]traceroute [host]mtr [host]nslookup [domain]dig [domain]host [domain]whois [domain]ping - Test connectivity
ping - Ping 4 times
traceroute - Trace route to host
mtr - Network diagnostic
nslookup - DNS lookup
dig - DNS lookup (detailed)
host - DNS lookup (simple)
whois - Domain info
Ports & Connections
netstat -tulnss -tulnss -tplsof -i :[port]nmap [host]netstat - Listening ports
ss - Listening ports (modern)
ss - TCP connections
lsof - Process using port
nmap - Port scan
Transfer
curl [url]curl -O [url]curl -I [url]wget [url]wget -c [url]scp [file] [user]@[host]:[path]rsync -avz [src] [dest]curl - Fetch URL content
curl - Download file
curl - Get headers only
wget - Download file
wget - Resume download
scp - Copy via SSH
rsync - Sync files
File Permissions
chmod 755 [file]chmod 644 [file]chmod +x [file]chmod -x [file]chmod u+w [file]chmod -R 755 [dir]chown [user] [file]chown [user]:[group] [file]chown -R [user] [dir]chgrp [group] [file]chmod - Set rwxr-xr-x
chmod - Set rw-r--r--
chmod - Add execute permission
chmod - Remove execute
chmod - Add write for owner
chmod - Recursive chmod
chown - Change owner
chown - Change owner and group
chown - Recursive chown
chgrp - Change group
💡 r=4, w=2, x=1. Example: 755 = rwxr-xr-x
Sudo & Users
sudo [command]sudo -isudo -u [user] [command]su - [user]visudosudo - Run as superuser
sudo - Root shell
sudo - Run as user
su - Switch user
visudo - Edit sudoers file
User Management
useradd [user]useradd -m [user]userdel [user]userdel -r [user]usermod -aG [group] [user]passwd [user]chage -l [user]useradd - Create user
useradd - Create with home dir
userdel - Delete user
userdel - Delete with home dir
usermod - Add user to group
passwd - Set password
chage - Password expiry info
Group Management
groupadd [group]groupdel [group]groups [user]cat /etc/passwdcat /etc/groupgroupadd - Create group
groupdel - Delete group
groups - Show user groups
cat - List all users
cat - List all groups
APT (Debian/Ubuntu)
apt updateapt upgradeapt install [pkg]apt remove [pkg]apt purge [pkg]apt autoremoveapt search [pkg]apt show [pkg]apt list --installeddpkg -i [file.deb]apt - Update package list
apt - Upgrade packages
apt - Install package
apt - Remove package
apt - Remove with config
apt - Remove unused
apt - Search packages
apt - Package info
apt - List installed
dpkg - Install .deb file
YUM/DNF (RHEL/Fedora)
yum updateyum install [pkg]yum remove [pkg]yum search [pkg]dnf install [pkg]rpm -ivh [file.rpm]yum - Update packages
yum - Install package
yum - Remove package
yum - Search packages
dnf - Install (Fedora)
rpm - Install .rpm file
Other Package Managers
pacman -S [pkg]pacman -Syusnap install [pkg]flatpak install [pkg]pacman - Install (Arch)
pacman - Update all (Arch)
snap - Install snap
flatpak - Install flatpak
Find Command
find [dir] -name [pattern]find [dir] -type ffind [dir] -type dfind [dir] -mtime -7find [dir] -size +100Mfind [dir] -exec [cmd] {} \;find [dir] -name '*.log' -deletefind - Find by name
find - Find files only
find - Find directories
find - Modified in 7 days
find - Larger than 100MB
find - Execute command
find - Find and delete
Services (systemd)
systemctl start [service]systemctl stop [service]systemctl restart [service]systemctl status [service]systemctl enable [service]systemctl disable [service]systemctl list-unitsjournalctl -u [service]journalctl -fsystemctl - Start service
systemctl - Stop service
systemctl - Restart service
systemctl - Service status
systemctl - Enable at boot
systemctl - Disable at boot
systemctl - List all units
journalctl - Service logs
journalctl - Follow system logs
Cron Jobs
crontab -ecrontab -lcrontab -rcrontab - Edit cron jobs
crontab - List cron jobs
crontab - Remove all cron jobs
💡 Format: minute hour day month weekday command
Useful Combos
find . -name '*.log' | xargs rmps aux | grep [name] | awk '{print $2}'du -sh * | sort -hr | head -10history | grep [cmd]watch -n 1 [command]time [command]xargs -I {} [cmd] {}find - Delete all .log files
ps - Get PIDs
du - Top 10 largest
history - Search history
watch - Run every second
time - Measure execution time
xargs - Use input as argument
Quick Reference
ls -la
find . -name "*"
grep pattern file
df -h
About Linux Commands
Linux commands are the foundation of system administration and development. This cheatsheet covers essential commands for file management, text processing, process control, networking, and more.