← All Cheat Sheets
Copy curl command
Linux Command Cheat Sheet Cheet says: The command line is your superpower!
Navigation
pwd # Print working directory
ls # List files
ls -la # List all with details
cd /path # Change directory
cd ~ # Go home
cd - # Go to previous directory
File Operations
Create touch file.txt # Create empty file
mkdir folder # Create directory
mkdir -p a/b/c # Create nested directories
Copy cp file.txt backup.txt
cp -r folder/ backup/ # Recursive
Move/Rename mv old.txt new.txt
mv file.txt /path/
Delete rm file.txt
rm -r folder/ # Recursive
rm -rf folder/ # Force (careful!)
View cat file.txt # Print entire file
less file.txt # Scrollable view
head -20 file.txt # First 20 lines
tail -20 file.txt # Last 20 lines
tail -f log.txt # Follow (live updates)
Searching
Find files find . -name "*.txt"
find . -type f -size +100M # Files > 100MB
find . -mtime -7 # Modified last 7 days
Search content grep "pattern" file.txt
grep -r "pattern" ./ # Recursive
grep -i "pattern" file.txt # Case insensitive
grep -v "pattern" file.txt # Invert match
Text Processing
Sort sort file.txt
sort -n file.txt # Numeric
sort -u file.txt # Unique
Count wc file.txt # Lines, words, chars
wc -l file.txt # Lines only
Unique uniq file.txt # Remove adjacent duplicates
sort file.txt | uniq
Cut columns cut -d',' -f1 file.csv
Replace sed 's/old/new/g' file.txt
sed -i 's/old/new/g' file.txt # In-place
Permissions
View ls -la
Change permissions chmod 755 file.sh # rwxr-xr-x
chmod +x file.sh # Add execute
chmod -w file.txt # Remove write
Change owner chown user:group file.txt
Common permissions: 644 - rw-r--r-- (files) 755 - rwxr-xr-x (executables, directories) 600 - rw------- (private files)
Process Management
View processes ps aux
top
htop # Better (install separately)
Find process pgrep nginx
ps aux | grep nginx
Kill process kill PID
kill -9 PID # Force
pkill nginx # By name
killall nginx
Background jobs command & # Run in background
jobs # List jobs
fg # Bring to foreground
bg # Send to background
nohup command & # Keep running after logout
Disk & Memory
Disk usage df -h # Filesystem usage
du -sh folder/ # Folder size
du -sh * | sort -h # Sorted sizes
Memory free -h
Find large files du -a . | sort -rn | head -20
Networking
Show IP ip addr
hostname -I
Test connectivity ping google.com
curl -I https://example.com
DNS lookup dig example.com
nslookup example.com
Ports ss -tulpn # Listening ports
netstat -tulpn # Alternative
Package Management
Debian/Ubuntu (apt) sudo apt update
sudo apt install package
sudo apt remove package
apt search package
Arch (pacman) sudo pacman -Syu
sudo pacman -S package
sudo pacman -R package
pacman -Ss package
RHEL/CentOS (yum/dnf) sudo dnf update
sudo dnf install package
System Info
uname -a # Kernel info
cat /etc/os-release # Distro info
hostname # Hostname
uptime # Uptime
whoami # Current user
id # User details
Redirection & Pipes
command > file # Output to file (overwrite)
command >> file # Output to file (append)
command 2> file # Errors to file
command &> file # Both to file
command1 | command2 # Pipe output
Examples ls -la > listing.txt
cat file.txt | grep "pattern" | sort