Essential Linux Commands for Website Owners

pwd                      # where am I
ls -lah                  # list with sizes and hidden files
cd /var/www/html
du -sh *                 # size of each item here
df -h                    # free disk space per filesystem
find . -name "*.log" -mtime +30   # log files older than 30 days

Files, permissions and ownership

cp -a source/ dest/      # copy preserving attributes
mv old new
rm -rf directory         # irreversible: check twice
chmod 644 file.php
chown -R deploy:deploy /var/www/site
tar -czf backup.tar.gz public_html/
tar -xzf backup.tar.gz

Processes, services and resources

top          # or htop for a friendlier view
free -m      # memory
ps aux --sort=-%cpu | head
kill -9 PID
systemctl status nginx
systemctl restart php8.3-fpm
journalctl -u nginx --since "1 hour ago"

Logs and troubleshooting

tail -f /var/log/nginx/error.log
grep -i "error" /var/log/php-fpm.log | tail -50
ss -tulpn                 # what is listening on which port
curl -I https://yourdomain.com   # response headers only
mysql -u root -p -e "SHOW PROCESSLIST;"

When a site breaks, read the error log before changing anything. Nearly every outage names its own cause in the last twenty lines.

Frequently asked questions

Do I need SSH access on shared hosting?

SSH is available on our plans and is very useful for backups, WP-CLI and searching logs, though everything essential can also be done in cPanel.

How do I stop deleting the wrong thing?

Use ls on the path first, avoid rm -rf with variables, and take a snapshot or backup before any bulk operation.

Need a hand applying this?

Our engineers can do it for you. Open a ticket and we will help.