Linux
Linux Commands Cheat Sheet
Essential Linux commands for system administration, DevOps, troubleshooting and SRE work.
Essential Linux Commands
pwdShow the current working directory.
lsList files and directories.
ls -laList all files, including hidden files, with detailed information.
cd /var/logChange to the /var/log directory.
mkdir appCreate a new directory named app.
touch app.logCreate an empty file named app.log.
cp file.txt backup.txtCopy a file.
mv old.txt new.txtMove or rename a file.
rm file.txtDelete a file.
cat app.logDisplay the contents of a file.
less app.logRead a large file page by page.
head -n 20 app.logShow the first 20 lines of a file.
tail -n 20 app.logShow the last 20 lines of a file.
tail -f app.logContinuously monitor new log entries.
grep 'ERROR' app.logSearch a file for lines containing ERROR.
find /var/log -name '*.log'Find log files under /var/log.
df -hCheck disk space usage in human-readable format.
du -sh /var/logShow the total size of a directory.
free -hCheck memory usage.
topMonitor running processes and system resources.
ps auxDisplay running processes.
kill <PID>Terminate a process using its process ID.
systemctl status nginxCheck the status of a systemd service.
systemctl restart nginxRestart a systemd service.
journalctl -u nginxView logs for a systemd service.
chmod 755 script.shChange file permissions.
chown user:user file.txtChange file ownership.
DevOps Troubleshooting Workflow
# Check disk df -h # Check memory free -h # Check running processes ps aux # Monitor system top # Check service systemctl status nginx # Check service logs journalctl -u nginx # Monitor application log tail -f /var/log/app.log
DevOpsToolbox Tip
When troubleshooting a Linux server, start by checking disk, memory, CPU, running processes, services and logs. This gives you a quick picture of the server's health before making changes.