Linux cheat sheet

Linux is the base operating system for most DevOps workloads.

On this page

Table of contents

Use this page for fast recall. Use Full documentation when you want the complete end-to-end path.

Quick workflow

A simple 5-step flow you can follow when using Linux in real work.

1) Setup

Install/run the tool and confirm version. Create a minimal config.

2) Small change

Do one small action end-to-end to prove the workflow.

3) Validate

Check output, logs, and status. Catch mistakes early.

4) Automate

Convert it into a repeatable script or pipeline step.

5) Productionize

Add safety: secrets, rollback, observability, and docs.

Workflows you will actually reuse

These are practical sequences you can copy into your own checklist or runbook.

Production incident triage (10 minutes)

Goal: Get from unknown outage to a clear hypothesis using evidence.

- Check service status and recent restarts (systemd).

- Inspect logs for the unit and system errors (journalctl, syslog).

- Check resource pressure (CPU, memory, disk).

- Check network listeners and upstream connectivity (ss, curl).

- Capture findings in notes and apply the smallest safe fix.

Key Concepts

- Filesystem

- Permissions

- Processes

Learning path (high-level):

- Shell basics

- User and permission management

- Service operations

Quick Start

Check OS details

Command

uname -a

List files

Command

ls -la

Find current path

Command

pwd

Common Commands

Short descriptions and practical intent. Search, filter, copy, and reuse.

Showing 30

Basics
uname -a

Kernel + OS information (fast environment check).

Basics
whoami

Show the current user (helps with permission issues).

Basics
pwd

Print current working directory.

Filesystem
ls -lah

List files with human sizes + hidden files.

Filesystem
cd -

Jump back to previous directory.

Filesystem
tree -L 2

Show folder tree up to depth 2 (install `tree` if missing).

Filesystem
cat file.txt

Print a file.

Filesystem
less file.txt

Read large files safely (search with `/`).

Filesystem
head -n 50 file.txt

Show first N lines.

Filesystem
tail -n 50 file.txt

Show last N lines.

Logs
tail -f /var/log/syslog

Follow logs live (Debian/Ubuntu).

Search
grep -R "needle" .

Recursive text search in current folder.

Search
rg "needle" .

Fast recursive search (ripgrep).

Search
find . -type f -name "*.log"

Find files by pattern.

Permissions
chmod 644 file.txt

Set permissions (rw-r--r--) for a file.

Permissions
chmod -R u+rwX,go-rwx secret_dir

Make dir private for owner.

Permissions
chown -R user:group /path

Change ownership recursively.

Permissions
id

Show uid/gid and groups for current user.

Processes
ps aux | head

List processes (classic view).

Processes
top

Interactive process viewer (CPU/mem).

Processes
free -h

Memory usage summary.

Storage
df -h

Disk usage by filesystem.

Storage
du -sh * | sort -h

Find large folders/files in current directory.

Networking
ss -lntp

Show listening TCP ports and processes.

Networking
curl -I https://example.com

Fetch HTTP headers (quick health check).

Networking
dig example.com

DNS lookup.

Services
systemctl status nginx

Check service status (systemd).

Services
systemctl restart nginx

Restart a service.

Logs
journalctl -u nginx -n 200 --no-pager

Show last logs for a systemd unit.

Permissions
sudo -l

Show allowed sudo commands (permission debugging).

Copyable snippets

Small blocks you can drop into your terminal, config, or runbook.

Find what is listening on a port

Use this when you get 'address already in use'.

bash

sudo ss -lntp | rg ":8080"

Basic service log triage

bash

sudo systemctl status nginx
sudo journalctl -u nginx -n 200 --no-pager

Troubleshooting checklist

When things break, follow this order to stay calm and move fast.

- If a command fails: confirm user identity, groups, and file permissions.

- If a service is down: `systemctl status`, then read logs: `journalctl -u <unit>`.

- If disk is full: `df -h` then locate large paths with `du -sh` and logs.

- If a port is unavailable: `ss -lntp` (or `lsof -i :PORT`) to find the process.

Pitfalls

The common mistakes that slow people down when using Linux.

- Copy-pasting commands without understanding inputs/outputs and side effects.

- Not documenting defaults (ports, paths, credentials) and then getting stuck in prod.

- Skipping logs and metrics when troubleshooting; always collect evidence first.

Mini lab (practice)

Do these tasks in order. You will feel the tool instead of just reading about it.

- Create a folder tree in `~/lab` and practice `pwd`, `ls -lah`, `cd -`, and `find` to locate files.

- Create a file, change permissions with `chmod`, and confirm with `ls -l`.

- Use `journalctl` or `/var/log/*` to find a failing service error line.

Interview prompts

Use these to test if you truly understand the basics (and can explain them clearly).

- Explain file permissions and how `chmod 644` differs from `chmod 755`.

- How do you find which process is listening on port 8080?

- What’s the difference between `systemctl` and `service`?

Official Docs

https://www.kernel.org/doc/html/latest/