Getting Started

Linux Cheatsheet

This comprehensive cheatsheet provides essential Linux commands organized by category for quick reference.

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

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

  • Ctrl+A - Beginning of line
  • Ctrl+E - End of line
  • Ctrl+U - Delete to beginning
  • Ctrl+K - Delete to end
  • Ctrl+W - Delete word
  • Alt+F - Forward one word
  • Alt+B - Back one word

Process Control

  • Ctrl+C - Interrupt process
  • Ctrl+D - End of input/Exit
  • Ctrl+Z - Suspend process
  • Ctrl+L - Clear screen

History

  • Ctrl+R - Search history
  • Ctrl+P / - Previous command
  • Ctrl+N / - Next command
  • !! - Repeat last command
  • !$ - Last argument of previous command

Copy/Paste

  • Ctrl+Shift+C - Copy
  • Ctrl+Shift+V - Paste

Tab Management

  • Ctrl+Shift+T - New tab
  • Ctrl+Shift+W - Close tab
  • Ctrl+PageUp/PageDown - Switch tabs

Advanced Tools

System Monitoring

vmstat            # Virtual memory stats
iostat            # I/O statistics
dmesg             # Kernel messages
journalctl        # System logs
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

  1. Tab Completion: Press Tab to auto-complete commands and paths
  2. Command History: Use history | grep [term] to search command history
  3. Pipes: Chain commands with | (e.g., ls -la | grep txt)
  4. Redirection: Use > to redirect output, >> to append
  5. Background Jobs: Add & to run commands in background
  6. Wildcards: Use * for multiple characters, ? for single character
  7. Command Substitution: Use $(command) or `command`
  8. Check Before Delete: Always use ls before rm with 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