Whether you're managing a VPS, deploying applications, or troubleshooting server issues, knowing the right Linux commands saves hours of work. This cheat sheet covers the 100 most essential commands organized by category, with practical examples you can use immediately.
Bookmark this page - it's your go-to reference for Linux command line operations in 2026.
File and Directory Commands
These are the most frequently used commands for navigating and managing files on any Linux system.
| Command | Description | Example |
|---|---|---|
ls | List directory contents | ls -la /var/www/ |
cd | Change directory | cd /etc/nginx/ |
pwd | Print working directory | pwd |
mkdir | Create directory | mkdir -p /var/www/mysite |
rmdir | Remove empty directory | rmdir old_folder |
cp | Copy files or directories | cp -r source/ dest/ |
mv | Move or rename files | mv old.txt new.txt |
rm | Remove files or directories | rm -rf /tmp/cache/ |
touch | Create empty file | touch index.html |
find | Search for files | find / -name "*.log" -size +100M |
locate | Find files by name (indexed) | locate nginx.conf |
ln | Create links | ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/ |
tree | Display directory tree | tree -L 2 /var/www/ |
stat | Display file details | stat index.html |
Key Examples
# List all files including hidden, with details
ls -la
# Create nested directories
mkdir -p /var/www/mysite/public/assets
# Copy directory recursively
cp -r /var/www/mysite/ /var/www/mysite-backup/
# Find files modified in the last 24 hours
find /var/log/ -name "*.log" -mtime -1
# Find and delete files older than 30 days
find /tmp/ -type f -mtime +30 -delete
rm -rf command permanently deletes files without confirmation. Always double-check the path before executing, especially when running as root. There is no recycle bin on Linux.
File Content and Text Commands
Commands for viewing, searching, and manipulating file contents - essential for reading logs and configuration files.
| Command | Description | Example |
|---|---|---|
cat | Display file contents | cat /etc/hostname |
less | View file with pagination | less /var/log/syslog |
head | Show first N lines | head -20 access.log |
tail | Show last N lines | tail -f /var/log/nginx/error.log |
grep | Search text patterns | grep -r "error" /var/log/ |
sed | Stream editor (find/replace) | sed -i 's/old/new/g' file.txt |
awk | Text processing | awk '{print $1}' access.log |
wc | Count lines/words/chars | wc -l access.log |
sort | Sort file contents | sort -rn sizes.txt |
uniq | Remove duplicate lines | sort file.txt | uniq -c |
diff | Compare two files | diff config.old config.new |
nano | Simple text editor | nano /etc/nginx/nginx.conf |
vim | Advanced text editor | vim /etc/hosts |
Powerful Grep Examples
# Search for errors in all log files
grep -r "error" /var/log/ --include="*.log"
# Case-insensitive search with line numbers
grep -in "failed" /var/log/auth.log
# Show lines before and after match (context)
grep -C 3 "502 Bad Gateway" /var/log/nginx/error.log
# Count occurrences
grep -c "404" /var/log/nginx/access.log
# Exclude patterns
grep -v "bot" access.log | grep "404"
Real-Time Log Monitoring
# Follow log in real time
tail -f /var/log/nginx/access.log
# Follow multiple logs
tail -f /var/log/nginx/access.log /var/log/nginx/error.log
# Follow with grep filter
tail -f /var/log/nginx/access.log | grep "500"
User and Permission Commands
| Command | Description | Example |
|---|---|---|
chmod | Change file permissions | chmod 755 script.sh |
chown | Change file ownership | chown www-data:www-data /var/www/ -R |
useradd | Create new user | useradd -m -s /bin/bash deploy |
usermod | Modify user | usermod -aG sudo deploy |
userdel | Delete user | userdel -r olduser |
passwd | Change password | passwd deploy |
sudo | Execute as superuser | sudo systemctl restart nginx |
su | Switch user | su - deploy |
groups | Show user groups | groups deploy |
id | Show user/group IDs | id deploy |
whoami | Current username | whoami |
Permission Reference
# Permission numbers explained:
# 7 = read (4) + write (2) + execute (1) = rwx
# 6 = read (4) + write (2) = rw-
# 5 = read (4) + execute (1) = r-x
# 4 = read only = r--
# 0 = no permissions = ---
# Common permission patterns:
chmod 755 directory/ # Owner: rwx, Group: r-x, Others: r-x
chmod 644 file.html # Owner: rw-, Group: r--, Others: r--
chmod 600 .env # Owner: rw-, Group: ---, Others: ---
chmod +x script.sh # Add execute permission for everyone
System Information Commands
| Command | Description | Example |
|---|---|---|
uname -a | System information | uname -a |
hostname | Show/set hostname | hostname |
uptime | System uptime | uptime |
date | Current date/time | date '+%Y-%m-%d %H:%M:%S' |
free | Memory usage | free -h |
top | Process monitor | top |
htop | Interactive process viewer | htop |
df | Disk space usage | df -h |
du | Directory size | du -sh /var/log/ |
lscpu | CPU information | lscpu |
lsb_release | OS version | lsb_release -a |
dmesg | Kernel messages | dmesg | tail -20 |
Quick Server Health Check
# One-liner server health check
echo "=== CPU ===" && uptime && echo "=== Memory ===" && free -h && echo "=== Disk ===" && df -h / && echo "=== Load ===" && cat /proc/loadavg
Network Commands
| Command | Description | Example |
|---|---|---|
ping | Test connectivity | ping -c 4 google.com |
curl | Transfer data from URLs | curl -I https://example.com |
wget | Download files | wget https://example.com/file.zip |
ss | Socket statistics | ss -tulnp |
ip addr | Show IP addresses | ip addr show |
dig | DNS lookup | dig example.com |
nslookup | DNS query | nslookup example.com |
traceroute | Trace network path | traceroute google.com |
scp | Secure copy over SSH | scp file.txt user@host:/path/ |
rsync | Sync files remotely | rsync -avz /local/ user@host:/remote/ |
ssh | Secure shell connection | ssh user@192.168.1.100 |
netstat | Network statistics | netstat -tulnp |
Useful Networking Examples
# Check which ports are open and listening
ss -tulnp
# Test if a specific port is open
curl -v telnet://localhost:3000
# Download a file and show progress
wget --progress=bar https://example.com/large-file.tar.gz
# Check HTTP response headers
curl -I https://yourdomain.com
# Sync files to remote server (deploy)
rsync -avz --delete ./dist/ user@server:/var/www/mysite/
Process Management
| Command | Description | Example |
|---|---|---|
ps | List processes | ps aux |
kill | Kill process by PID | kill -9 1234 |
killall | Kill processes by name | killall nginx |
systemctl | Manage systemd services | systemctl restart nginx |
journalctl | View systemd logs | journalctl -u nginx -f |
bg | Resume job in background | bg %1 |
fg | Bring job to foreground | fg %1 |
nohup | Run immune to hangups | nohup ./script.sh & |
screen | Terminal multiplexer | screen -S mysession |
crontab | Schedule tasks | crontab -e |
Essential systemctl Commands
# Manage services
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl status nginx
# Enable/disable on boot
sudo systemctl enable nginx
sudo systemctl disable nginx
# View all running services
systemctl list-units --type=service --state=running
# View service logs
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx -f # Follow in real time
Cron Job Schedule Format
# Cron format: minute hour day month weekday command
# ┌───────────── minute (0-59)
# │ ┌───────────── hour (0-23)
# │ │ ┌───────────── day of month (1-31)
# │ │ │ ┌───────────── month (1-12)
# │ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
# * * * * * command
# Examples:
0 2 * * * /usr/local/bin/backup.sh # Daily at 2:00 AM
*/5 * * * * /usr/local/bin/health-check.sh # Every 5 minutes
0 0 * * 0 certbot renew # Weekly on Sunday midnight
0 */6 * * * /usr/bin/apt update # Every 6 hours
Package Management
APT (Ubuntu/Debian)
# Update package lists
sudo apt update
# Upgrade all packages
sudo apt upgrade -y
# Install a package
sudo apt install nginx -y
# Remove a package
sudo apt remove nginx
# Remove package and config files
sudo apt purge nginx
# Search for packages
apt search nodejs
# Show package info
apt show nginx
# Clean up unused packages
sudo apt autoremove -y
Snap Packages
# Install a snap package
sudo snap install node --classic
# List installed snaps
snap list
# Update all snaps
sudo snap refresh
Disk and Storage Commands
| Command | Description | Example |
|---|---|---|
df -h | Disk space in human-readable | df -h |
du -sh | Directory size | du -sh /var/log/ |
lsblk | List block devices | lsblk |
mount | Mount filesystem | mount /dev/sdb1 /mnt/data |
umount | Unmount filesystem | umount /mnt/data |
fdisk | Partition management | fdisk -l |
tar | Archive files | tar -czf backup.tar.gz /var/www/ |
zip/unzip | Compress/decompress | zip -r archive.zip folder/ |
gzip | Compress files | gzip large-file.log |
Find Large Files and Directories
# Find top 10 largest files
find / -type f -exec du -h {} + 2>/dev/null | sort -rh | head -10
# Find top 10 largest directories
du -h --max-depth=1 / 2>/dev/null | sort -rh | head -10
# Check disk usage by directory
du -sh /var/* | sort -rh
# Find files larger than 100MB
find / -type f -size +100M -exec ls -lh {} \;
VPS Management Commands
These commands are specifically useful for managing VPS servers day-to-day. For a complete deployment guide, see our website deployment tutorial.
Nginx Management
# Test configuration
sudo nginx -t
# Reload without downtime
sudo systemctl reload nginx
# View access logs
tail -f /var/log/nginx/access.log
# View error logs
tail -f /var/log/nginx/error.log
# List enabled sites
ls -la /etc/nginx/sites-enabled/
Firewall (UFW)
# Check status
sudo ufw status verbose
# Allow a port
sudo ufw allow 8080
# Allow specific IP
sudo ufw allow from 192.168.1.100
# Deny a port
sudo ufw deny 3306
# Delete a rule
sudo ufw delete allow 8080
# Reset all rules
sudo ufw reset
SSL Certificate Management
# Install Certbot
sudo apt install certbot python3-certbot-nginx -y
# Get SSL certificate
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
# Renew all certificates
sudo certbot renew
# Check certificate status
sudo certbot certificates
# Test auto-renewal
sudo certbot renew --dry-run
Server Backup
# Full website backup
tar -czf /backups/website-$(date +%Y%m%d).tar.gz /var/www/
# Database backup (MySQL)
mysqldump -u root -p mydb > /backups/db-$(date +%Y%m%d).sql
# Database backup (PostgreSQL)
pg_dump mydb > /backups/db-$(date +%Y%m%d).sql
# Sync backup to remote server
rsync -avz /backups/ user@backup-server:/backups/
Frequently Asked Questions
What are the most important Linux commands to learn first?
Start with ls, cd, cp, mv, rm, cat, grep, sudo, chmod, and systemctl. These 10 commands cover 80% of daily tasks. Then expand to networking and process management commands.
How do I find which process is using a specific port?
Use ss -tulnp | grep :PORT or lsof -i :PORT. For example, ss -tulnp | grep :80 shows what's using port 80. This is essential for debugging port conflicts.
How do I check server resource usage?
Use htop for an interactive view, free -h for memory, df -h for disk space, and uptime for CPU load averages. For a quick overview, combine them in a single command.
What's the difference between rm and rm -rf?
rm deletes individual files. rm -r deletes directories recursively. rm -rf forces deletion without confirmation. Always double-check paths before using rm -rf as it cannot be undone.
How do I make a script executable?
Use chmod +x script.sh to add execute permission, then run it with ./script.sh. For system-wide access, move the script to /usr/local/bin/.
Conclusion
This Linux commands cheat sheet covers the 100 most essential commands you'll need for daily server management. Bookmark this page and refer back to it whenever you need a quick reference.
Remember: you don't need to memorize every command. Tools like VPS Commander can handle most server management tasks through a visual interface. But knowing these commands gives you the power to handle any situation that comes up.