← Back to DevOpsToolbox

Linux

Linux Commands Cheat Sheet

Essential Linux commands for system administration, DevOps, troubleshooting and SRE work.

Essential Linux Commands

pwd

Show the current working directory.

ls

List files and directories.

ls -la

List all files, including hidden files, with detailed information.

cd /var/log

Change to the /var/log directory.

mkdir app

Create a new directory named app.

touch app.log

Create an empty file named app.log.

cp file.txt backup.txt

Copy a file.

mv old.txt new.txt

Move or rename a file.

rm file.txt

Delete a file.

cat app.log

Display the contents of a file.

less app.log

Read a large file page by page.

head -n 20 app.log

Show the first 20 lines of a file.

tail -n 20 app.log

Show the last 20 lines of a file.

tail -f app.log

Continuously monitor new log entries.

grep 'ERROR' app.log

Search a file for lines containing ERROR.

find /var/log -name '*.log'

Find log files under /var/log.

df -h

Check disk space usage in human-readable format.

du -sh /var/log

Show the total size of a directory.

free -h

Check memory usage.

top

Monitor running processes and system resources.

ps aux

Display running processes.

kill <PID>

Terminate a process using its process ID.

systemctl status nginx

Check the status of a systemd service.

systemctl restart nginx

Restart a systemd service.

journalctl -u nginx

View logs for a systemd service.

chmod 755 script.sh

Change file permissions.

chown user:user file.txt

Change 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.