Linux Command Cheat Sheet
Everyday server commands, searchable, with copy buttons.
Files and folders
ls -lah | List files with sizes and hidden entries | |
cd /var/log | Change directory | |
cp -r src/ dest/ | Copy a folder | |
mv old new | Move or rename | |
rm -i file | Delete a file, asking first | |
find /var -name "*.log" -size +100M | Find large log files | |
tar -czf backup.tar.gz /srv/app | Create a compressed archive |
Viewing and searching
less /var/log/syslog | Page through a file | |
tail -f /var/log/nginx/error.log | Follow a log live | |
grep -rin "error" /var/log | Search text recursively |
System and resources
uptime | Load average and running time | |
free -h | Memory use | |
df -h | Disk space per filesystem | |
du -xh --max-depth=1 / | sort -h | Largest folders | |
top | Live process view | |
journalctl -p err -b | Errors since boot |
Services (systemd)
systemctl status nginx | Check a service | |
sudo systemctl restart nginx | Restart a service | |
sudo systemctl enable --now nginx | Start now and at boot | |
journalctl -u nginx -f | Follow service logs |
Packages (Debian/Ubuntu)
sudo apt update | Refresh package lists | |
sudo apt upgrade | Install updates | |
sudo apt install nginx | Install a package | |
sudo apt autoremove | Remove unused dependencies |
Packages (AlmaLinux/Rocky)
sudo dnf upgrade | Install updates | |
sudo dnf install nginx | Install a package |
Networking
ip -brief address | Network addresses | |
ss -tulpn | Listening ports and processes | |
curl -I https://example.com | Fetch response headers | |
ping -c 4 1.1.1.1 | Test connectivity | |
dig example.com +short | DNS lookup |
Users, permissions and SSH
sudo adduser deploy | Create a user | |
sudo usermod -aG sudo deploy | Allow sudo (Debian/Ubuntu) | |
chmod 600 ~/.ssh/authorized_keys | Restrict key file permissions | |
sudo chown -R www-data:www-data /var/www/site | Change ownership | |
ssh-keygen -t ed25519 | Create a key pair (on your computer) | |
sudo sshd -t | Validate SSH configuration before reloading |