Linux Commands Cheat Sheet
Organized by scenario, perfect for daily operations and troubleshooting.
1. Files and Directories
ls -al pwd cd /path cp -r src dst mv old new rm -rf target mkdir -p /path/to/dir
2. System and Resources
uname -a uptime free -h df -h top htop # Install with: sudo apt install htop (Ubuntu) or sudo dnf install -y htop (Rocky)
3. Processes and Services
ps aux | grep nginx sudo systemctl status nginx --no-pager sudo systemctl restart nginx sudo systemctl enable nginx
4. Network Troubleshooting
ip a ss -tulpen ping -c 4 8.8.8.8 curl -I https://example.com traceroute example.com # Install with: sudo apt install traceroute (Ubuntu) or sudo dnf install -y traceroute (Rocky)
5. Log Viewing
sudo journalctl -u nginx --no-pager | tail -n 50 tail -f /var/log/nginx/access.log tail -f /var/log/nginx/error.log dmesg | tail -n 50
6. Firewall (firewalld - Rocky/AlmaLinux)
sudo firewall-cmd --list-services sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload
6. Firewall (ufw - Ubuntu/Debian)
sudo ufw status sudo ufw allow http sudo ufw allow https sudo ufw enable
7. Package Management (APT - Ubuntu/Debian)
sudo apt update sudo apt upgrade -y sudo apt install -y package-name sudo apt search package-name sudo apt remove package-name
8. Package Management (DNF - Rocky/AlmaLinux)
sudo dnf makecache sudo dnf search package-name sudo dnf install -y package-name sudo dnf update -y