Skip to content

Cheat sheet: All cheat sheets

Every cheat sheet on one page: Linux, Docker, Kubernetes, Git, Terraform and Helm, each command broken down part by part.

Index
  • #cheatsheet
  • #linux
  • #docker
  • #kubernetes
  • #git
  • #terraform
  • #helm
Updated

Also:cheat sheet · cheatsheet · reference · quick reference · all commands

Every cheat sheet on one page. Use the filter to find a flag, or open one tool’s sheet. Each tool has a folder in the sidebar with a page per section.

688 items
Click a command to see what each part does.

Navigate & list13

  • cd <dir>Linux & shellGo into a folder

    What each part does

    1. cdchange directory (a shell built-in)
    2. <dir>relative path (logs) or absolute path (/var/log)
    Linux & shell cheat sheet →
  • cd ~Linux & shellGo to your home folder

    What each part does

    1. cdchange directory
    2. ~your home directory (/home/<user>); plain "cd" with no argument does the same
    Linux & shell cheat sheet →
  • cd ..; cd -Linux & shellGo up one level / back to the previous folder

    What each part does

    1. cd ..".." is the parent of the current folder
    2. ;then
    3. cd -jump back to the folder you were in before (and print it)
    Linux & shell cheat sheet →
  • pwdLinux & shellShow where you are

    What each part does

    1. pwdprint working directory: the full path of the current folder
    Linux & shell cheat sheet →
  • lsLinux & shellList files

    What each part does

    1. lslist the current folder (names only, hidden dot-files not shown)
    Linux & shell cheat sheet →
  • ls -lLinux & shellLong listing: permissions, owner, size, date

    What each part does

    1. lslist directory contents
    2. -llong format: permissions, links, owner, group, size in bytes, modified date, name
    Linux & shell cheat sheet →
  • ls -laLinux & shellInclude hidden files (.env, .git …)

    What each part does

    1. -llong format
    2. -a--all: also show entries starting with "." (including . and ..)

    Tip ls -lA shows hidden files but leaves out . and ..

    Linux & shell cheat sheet →
  • ls -lhLinux & shellLong listing with readable sizes

    What each part does

    1. -llong format
    2. -h--human-readable: sizes like 4.0K, 12M, 1.3G instead of bytes (works with -l)
    Linux & shell cheat sheet →
  • ls -ltrLinux & shellNewest files last (great for log folders)

    What each part does

    1. -llong format
    2. -tsort by modification time, newest first
    3. -r--reverse: flip the order, so the newest ends up at the bottom next to your prompt
    Linux & shell cheat sheet →
  • ls -lhSLinux & shellBiggest files first

    What each part does

    1. -l -hlong format with readable sizes
    2. -Ssort by size, largest first
    Linux & shell cheat sheet →
  • ls -d */Linux & shellList only sub-folders

    What each part does

    1. -d--directory: list the folders themselves, not what is inside them
    2. */shell glob that matches only directories
    Linux & shell cheat sheet →
  • ls -R <dir>Linux & shellList everything below, recursively

    What each part does

    1. -R--recursive: list every sub-folder too
    Linux & shell cheat sheet →
  • tree -L 2 <dir>Linux & shellFolder tree, two levels deep

    What each part does

    1. treedraw the folder structure (install it: apt install tree)
    2. -L 2limit depth to 2 levels
    Linux & shell cheat sheet →

Files: create, copy, view, compress42

  • mkdir -p <path/to/dir>Linux & shellCreate a folder (and parents) in one go

    What each part does

    1. mkdirmake directory
    2. -pcreate missing parent folders too; no error if it already exists
    Linux & shell cheat sheet →
  • touch <file>Linux & shellCreate an empty file / update its timestamp

    What each part does

    1. touchcreate the file if missing; if it exists, set its modified time to now
    Linux & shell cheat sheet →
  • cp <src> <dest>Linux & shellCopy a file

    What each part does

    1. cpcopy
    2. <src>file to copy
    3. <dest>new file name, or a folder to copy into
    Linux & shell cheat sheet →
  • cp -r <src-dir> <dest-dir>Linux & shellCopy a folder with everything in it

    What each part does

    1. -r--recursive: copy directories and their contents
    Linux & shell cheat sheet →
  • cp -a <src> <dest>Linux & shellCopy keeping permissions, owner and times (backups)

    What each part does

    1. -a--archive: recursive + keep symlinks, permissions, ownership and timestamps
    Linux & shell cheat sheet →
  • cp -i <src> <dest>Linux & shellCopy but ask before overwriting

    What each part does

    1. -i--interactive: prompt before overwriting an existing file
    Linux & shell cheat sheet →
  • mv <old-name> <new-name>Linux & shellRename a file or folder

    What each part does

    1. mvmove: within the same folder this is a rename
    Linux & shell cheat sheet →
  • mv <file1> <file2> <dir>/Linux & shellMove files into a folder

    What each part does

    1. <file1> <file2>one or more sources
    2. <dir>/destination folder (the trailing / makes it clear it is a folder)

    Tip Add -i to be asked before overwriting, -n to never overwrite.

    Linux & shell cheat sheet →
  • rm <file>Linux & shellDelete a fileCaution

    What each part does

    1. rmremove (no recycle bin: it is gone)
    Linux & shell cheat sheet →
  • rm -i <files>Linux & shellDelete, but confirm each fileCaution

    What each part does

    1. -iprompt before every removal
    Linux & shell cheat sheet →
  • rm -rf <dir>Linux & shellDelete a folder and everything in itDestructive

    What each part does

    1. -r--recursive: remove directories and their contents
    2. -f--force: never prompt, ignore files that don't exist
    3. <dir>double-check this path: there is no undo

    Tip Run ls <dir> first. Never run it with a variable that might be empty (rm -rf "$DIR/").

    Linux & shell cheat sheet →
  • rmdir <dir>Linux & shellDelete an empty folder

    What each part does

    1. rmdirremove a directory only if it is empty (safe)
    Linux & shell cheat sheet →
  • ln -s <target> <link-name>Linux & shellCreate a symbolic link (shortcut)

    What each part does

    1. lnmake links
    2. -s--symbolic: a symlink pointing to <target> (without -s it makes a hard link)
    3. <target>the real file or folder
    4. <link-name>the shortcut to create
    Linux & shell cheat sheet →
  • cat <file>Linux & shellPrint a file

    What each part does

    1. catconcatenate: print one or more files to the screen
    Linux & shell cheat sheet →
  • cat -n <file>Linux & shellPrint with line numbers

    What each part does

    1. -n--number: number every output line
    Linux & shell cheat sheet →
  • less <file>Linux & shellRead a long file page by page

    What each part does

    1. lessscroll a file: Space/b = page down/up, /text = search, n = next match, G = end, q = quit
    Linux & shell cheat sheet →
  • head -n 20 <file>Linux & shellFirst lines of a file

    What each part does

    1. headstart of a file
    2. -n 20how many lines (default 10)
    Linux & shell cheat sheet →
  • tail -n 50 <file>Linux & shellLast lines of a file

    What each part does

    1. tailend of a file
    2. -n 50how many lines (default 10); add -f to keep following
    Linux & shell cheat sheet →
  • wc -l <file>Linux & shellCount lines, words, bytes

    What each part does

    1. wcword count
    2. -lcount lines only (-w words, -c bytes)
    Linux & shell cheat sheet →
  • diff -u <old-file> <new-file>Linux & shellCompare two files

    What each part does

    1. diffshow differences (exit 0 = same, 1 = different)
    2. -uunified format: - removed lines, + added lines, 3 lines of context
    Linux & shell cheat sheet →
  • file <file>Linux & shellWhat kind of file is this?

    What each part does

    1. filedetect the type: text, ELF binary, gzip, JSON…
    Linux & shell cheat sheet →
  • stat <file>Linux & shellSize, permissions and timestamps of a file

    What each part does

    1. statdetailed metadata: size, inode, permissions, access/modify/change times
    Linux & shell cheat sheet →
  • zip -r <archive>.zip <dir>Linux & shellZip a folder

    What each part does

    1. zipcreate a .zip archive
    2. -rinclude folders recursively
    Linux & shell cheat sheet →
  • unzip <archive>.zip -d <dir>Linux & shellUnzip into a folder

    What each part does

    1. -d <dir>extract into <dir> instead of the current folder
    Linux & shell cheat sheet →
  • gzip <file>; gunzip <file>.gzLinux & shellCompress / decompress one file

    What each part does

    1. gzip <file>replace <file> with <file>.gz
    2. gunziprestore the original
    Linux & shell cheat sheet →
  • tar -tf <archive>.tar.gzLinux & shellList what is inside a tarball

    What each part does

    1. -tlist contents
    2. -farchive file name
    Linux & shell cheat sheet →
  • grep -rn "<text>" <dir>Linux & shellSearch text in all files under a folder

    What each part does

    1. grepprint lines matching a pattern
    2. -rrecurse into sub-directories
    3. -nshow the line number of each match
    4. "<text>"the pattern (quote it if it has spaces or special characters)
    5. <dir>where to start searching
    Linux & shell cheat sheet →
  • grep -rni --include="*.yaml" "<pattern>" <dir>Linux & shellCase-insensitive search in one file type only

    What each part does

    1. -r -nrecursive, with line numbers
    2. -iignore upper/lower case
    3. --include="*.yaml"only search files whose name matches the glob
    4. "<pattern>"regular expression to find

    Tip Useful extras: -l (only file names), -v (lines that do NOT match), -w (whole word), -C 3 (3 lines of context).

    Linux & shell cheat sheet →
  • find <dir> -name "*.log" -mtime +7 -deleteLinux & shellFind and delete log files older than 7 daysDestructive

    What each part does

    1. find <dir>walk the directory tree starting at <dir>
    2. -name "*.log"file name matches the pattern (quoted so the shell does not expand it)
    3. -mtime +7last modified more than 7 days ago
    4. -deletedelete each match

    Tip Run it with -print instead of -delete first to see what would go.

    Linux & shell cheat sheet →
  • find <dir> -type f -size +100MLinux & shellFind big files

    What each part does

    1. -type fregular files only (d = directories)
    2. -size +100Mlarger than 100 MiB ("+" = more than, "-" = less than)
    Linux & shell cheat sheet →
  • find <dir> -name "*.tmp" -print0 | xargs -0 rm -fLinux & shellRun a command on every found file (safe with spaces)Destructive

    What each part does

    1. -print0print each name ending with a NUL byte instead of a newline
    2. |pipe the names to xargs
    3. xargs -0read NUL-separated names, so spaces/newlines in names are safe
    4. rm -fremove the files, no prompts
    Linux & shell cheat sheet →
  • tail -F <file> | grep --line-buffered "<word>"Linux & shellFollow a log and show only matching lines

    What each part does

    1. tailshow the end of a file
    2. -Ffollow new lines and keep following when the file is rotated or recreated
    3. |stream new lines into grep
    4. grep --line-bufferedprint each match immediately instead of buffering
    5. "<word>"text to look for, e.g. ERROR
    Linux & shell cheat sheet →
  • sed -n '<start>,<end>p' <file>Linux & shellShow lines N to M of a file

    What each part does

    1. sedstream editor
    2. -ndon't print every line automatically
    3. '<start>,<end>p'address range (line numbers) + p = print those lines
    Linux & shell cheat sheet →
  • sed -i.bak 's/<old>/<new>/g' <file>Linux & shellReplace text in a file in place (keep a backup)Caution

    What each part does

    1. -i.bakedit the file in place and save the original as <file>.bak
    2. s/<old>/<new>/substitute: regex <old> → <new>
    3. greplace every match on a line, not just the first
    Linux & shell cheat sheet →
  • sort <file> | uniq -c | sort -rn | headLinux & shellCount duplicate lines, most frequent first

    What each part does

    1. sort <file>sort lines so duplicates sit next to each other
    2. uniq -ccollapse adjacent duplicates and prefix each with its count
    3. sort -rnsort by that number (-n numeric) in reverse order (-r)
    4. headtop 10
    Linux & shell cheat sheet →
  • awk '{print $1}' access.log | sort | uniq -c | sort -rn | headLinux & shellTop client IPs in an access log

    What each part does

    1. awk '{print $1}'print the first whitespace-separated field of every line (the client IP)
    2. sort | uniq -cgroup identical IPs and count them
    3. sort -rn | headhighest counts first, top 10
    Linux & shell cheat sheet →
  • grep -c "<pattern>" <file>; wc -l <file>Linux & shellCount lines / matches

    What each part does

    1. grep -ccount matching lines instead of printing them
    2. wc -lcount all lines in the file
    Linux & shell cheat sheet →
  • sort -t: -k3,3n /etc/passwdLinux & shellSort a delimited file by a numeric column

    What each part does

    1. -t:fields are separated by ":"
    2. -k3,3sort key is field 3 only
    3. ncompare that key as a number
    Linux & shell cheat sheet →
  • tar -czvf <name>.tar.gz <dir>Linux & shellCreate a gzip tarball

    What each part does

    1. -ccreate an archive
    2. -zcompress with gzip
    3. -vlist files as they are added
    4. -f <name>.tar.gzarchive file name (must come right after f)
    Linux & shell cheat sheet →
  • tar -xzvf <name>.tar.gz -C <dest>Linux & shellExtract a tarball into a folder

    What each part does

    1. -xextract
    2. -z -v -fgzip, verbose, archive file
    3. -C <dest>change to <dest> before extracting
    Linux & shell cheat sheet →
  • rsync -avzn --delete <src>/ <user>@<host>:<dest>/Linux & shellSync a folder to a server (preview first)Caution

    What each part does

    1. -aarchive mode: recursive, keep permissions, times, owner, symlinks
    2. -vverbose
    3. -zcompress during transfer
    4. -ndry run: show what would change. Remove it to really sync
    5. --deletedelete files on the destination that are not in the source
    6. <src>/trailing slash = copy the folder’s contents, not the folder itself
    Linux & shell cheat sheet →
  • scp -r -P <port> <src> <user>@<host>:<path>Linux & shellCopy a folder to a server over SSH

    What each part does

    1. -rcopy directories recursively
    2. -P <port>SSH port (capital P; lowercase -p means preserve times)
    3. <user>@<host>:<path>remote destination
    Linux & shell cheat sheet →

Error codes & fixes55

  • curl -sSIL <url>301 / 302Error codes & fixesRedirect: see every hop

    What it means

    301 Moved Permanently / 302 Found: the resource is at another URL, given in the Location header. Not an error by itself.

    Usual causes & fixes

    • Redirect loop (ERR_TOO_MANY_REDIRECTS): HTTP→HTTPS redirect behind a load balancer that terminates TLS. The app sees HTTP every time; trust X-Forwarded-Proto.
    • Wrong host or missing trailing slash in the Location header.
    • Old path after a move: update the link or add a permanent redirect.

    Diagnose: what each part of the command does

    1. curlmake an HTTP request
    2. -s -Sno progress bar, but still show errors
    3. -Iheaders only (HEAD request)
    4. -Lfollow redirects, printing the headers of every hop
    5. <url>the address you are testing
    Error codes & fixes cheat sheet →
  • curl -v -X POST -H "Content-Type: application/json" -d @<file>.json <url>400Error codes & fixesBad Request: look at exactly what you send

    What it means

    The server will not process the request because of a client error: malformed syntax, invalid framing, bad parameters.

    Usual causes & fixes

    • Invalid JSON: check it with jq . <file>.json.
    • Missing or wrong Content-Type header.
    • Headers or cookies too large (nginx: "Request Header Or Cookie Too Large" → raise large_client_header_buffers).
    • Required field missing: read the response body, APIs usually say which one.

    Diagnose: what each part of the command does

    1. -vverbose: print request and response headers
    2. -X POSTHTTP method
    3. -H "Content-Type: application/json"tell the server the body is JSON
    4. -d @<file>.jsonsend the body from a file (@ = read file)
    Error codes & fixes cheat sheet →
  • curl -i -H "Authorization: Bearer <token>" <url>401Error codes & fixesUnauthorized: test the credentials

    What it means

    "Unauthenticated": the request has no valid credentials. The WWW-Authenticate response header says which scheme is expected.

    Usual causes & fixes

    • Token missing, expired or for the wrong environment.
    • Wrong scheme: Bearer vs Basic vs an API-key header.
    • Clock skew makes a fresh JWT look expired/not-yet-valid: check timedatectl.
    • A proxy (basic auth, oauth2-proxy) in front of the app asks for its own login.

    Diagnose: what each part of the command does

    1. -iinclude response headers in the output
    2. -H "Authorization: Bearer <token>"send the token the way the API expects
    Error codes & fixes cheat sheet →
  • namei -l <path-to-file>403Error codes & fixesForbidden: check the server log and the file path

    What it means

    The server knows who you are but refuses access.

    Usual causes & fixes

    • nginx/Apache: the web server user needs x on every parent folder and r on the file (see namei output). Check sudo tail -n 50 /var/log/nginx/error.log.
    • Folder requested but no index file and autoindex off → 403.
    • IP allow/deny list, WAF rule, or a cloud bucket policy.
    • Kubernetes API "forbidden": RBAC. Check with kubectl auth can-i <verb> <resource> -n <namespace>.

    Diagnose: what each part of the command does

    1. nameifollow a path one component at a time
    2. -llong format: owner, group and permissions of EVERY directory on the way
    3. <path-to-file>e.g. /var/www/site/index.html
    Error codes & fixes cheat sheet →
  • curl -sS -o /dev/null -w "%{http_code} %{url_effective}\n" -L <url>404Error codes & fixesNot Found: what does the server actually return?

    What it means

    The server cannot find the requested resource. For an API it can also mean the endpoint exists but the object does not.

    Usual causes & fixes

    • Typo or wrong path/base path (e.g. app served under /api but called at /).
    • nginx location / root / alias points somewhere else: nginx -T | grep -n -A5 "location".
    • Kubernetes ingress host or path does not match (see the next entry).
    • Static site: file not deployed, or case-sensitive name (Index.html vs index.html).

    Diagnose: what each part of the command does

    1. -sSquiet, show errors
    2. -o /dev/nulldiscard the body
    3. -w "%{http_code} %{url_effective}\n"print the final status and the final URL after redirects
    4. -Lfollow redirects
    Error codes & fixes cheat sheet →
  • kubectl get ingress -A; kubectl describe ingress <ingress> -n <namespace>404Error codes & fixesNot Found behind a Kubernetes ingress

    What it means

    The ingress controller answered but no rule matched the host + path (often the controller's default 404 page).

    Usual causes & fixes

    • Host header does not match the host: rule (test with curl -H "Host: <host>" http://<ingress-ip>/<path>).
    • pathType: Exact vs Prefix, or a rewrite annotation changing the path.
    • Wrong ingressClassName, so a different controller (or none) owns the ingress.

    Diagnose: what each part of the command does

    1. get ingress -Aall ingresses with their HOSTS and ADDRESS
    2. describe ingress <ingress>rules: host + path → service:port, and events
    3. -n <namespace>namespace of the ingress
    Error codes & fixes cheat sheet →
  • curl -i -X OPTIONS <url>405Error codes & fixesMethod Not Allowed: which methods are allowed?

    What it means

    The method (GET/POST/PUT…) is known but not supported for this URL.

    Usual causes & fixes

    • POST to a static location, or GET to a POST-only endpoint.
    • A proxy or ingress rule only allows some methods.
    • CORS preflight (OPTIONS) not handled by the API.

    Diagnose: what each part of the command does

    1. -ishow response headers
    2. -X OPTIONSask the server which methods it supports (Allow header)
    Error codes & fixes cheat sheet →
  • grep -rn "client_max_body_size" /etc/nginx/413Error codes & fixesContent Too Large: find the body size limit

    What it means

    The request body is larger than the server allows.

    Usual causes & fixes

    • nginx: raise client_max_body_size 50m; in the http/server/location block, then sudo nginx -t && sudo systemctl reload nginx.
    • ingress-nginx: annotation nginx.ingress.kubernetes.io/proxy-body-size: "50m".
    • App or framework upload limit as well.

    Diagnose: what each part of the command does

    1. grep -rnsearch recursively with line numbers
    2. "client_max_body_size"nginx directive that limits upload size
    3. /etc/nginx/nginx config folder
    Error codes & fixes cheat sheet →
  • curl -sI <url> | grep -i -E "retry-after|ratelimit"429Error codes & fixesToo Many Requests: read the rate-limit headers

    What it means

    You sent too many requests in a given time (rate limiting).

    Usual causes & fixes

    • Wait for Retry-After seconds; add backoff with jitter to clients.
    • Retry storm from many pods sharing one egress IP / API key.
    • Docker Hub "toomanyrequests" on image pulls: docker login or use a mirror.

    Diagnose: what each part of the command does

    1. curl -sIquiet, headers only
    2. | grep -i -Ecase-insensitive, extended regex filter
    3. "retry-after|ratelimit"Retry-After and X-RateLimit-* headers
    Error codes & fixes cheat sheet →
  • kubectl logs <pod> -n <namespace> --tail=100500Error codes & fixesInternal Server Error: read the application logs

    What it means

    Generic "the server hit something it does not know how to handle": the app crashed or threw.

    Usual causes & fixes

    • Unhandled exception: the stack trace is in the app log (docker logs <container> / journalctl -u <service>).
    • Bad config or missing env var after a deploy: compare with the previous version, roll back if needed.
    • Downstream dependency (DB, cache) down or credentials rotated.

    Diagnose: what each part of the command does

    1. kubectl logs <pod>app output (stack traces end up here)
    2. -n <namespace>namespace
    3. --tail=100last 100 lines
    Error codes & fixes cheat sheet →
  • sudo tail -n 50 /var/log/nginx/error.log502Error codes & fixesBad Gateway: the proxy got no valid answer from the app

    What it means

    The gateway/proxy received an invalid response from the upstream (your app).

    Usual causes & fixes

    • App not running or crashed: check systemctl status <service> / pod status.
    • Proxy points to the wrong port (proxy_pass / Service targetPort).
    • App listens on 127.0.0.1 inside a container instead of 0.0.0.0.
    • TLS mismatch: proxy speaks HTTP to an HTTPS backend or the reverse.

    Diagnose: what each part of the command does

    1. sudolog files are root-only
    2. tail -n 50last 50 lines
    3. /var/log/nginx/error.lognginx error log: says why the upstream failed (connection refused, reset, …)
    Error codes & fixes cheat sheet →
  • kubectl get endpointslices -l kubernetes.io/service-name=<service> -n <namespace>502 / 503Error codes & fixesKubernetes service has no ready pods behind it

    What it means

    Empty ENDPOINTS = the Service has nowhere to send traffic, so the ingress returns 502/503.

    Usual causes & fixes

    • Service selector does not match the pod labels: compare kubectl get svc <service> -o yaml with kubectl get pods --show-labels.
    • Pods exist but are not Ready: readiness probe failing (kubectl describe pod <pod> → Events).
    • targetPort does not match the containerPort.

    Diagnose: what each part of the command does

    1. get endpointslicesthe pod IPs a Service actually sends traffic to
    2. -l kubernetes.io/service-name=<service>only the slices of that Service
    3. -n <namespace>namespace
    Error codes & fixes cheat sheet →
  • kubectl get pods -l app=<app> -n <namespace> -o wide503Error codes & fixesService Unavailable: are the pods ready?

    What it means

    The server is not ready to handle the request: down for maintenance or overloaded. Often sent with Retry-After.

    Usual causes & fixes

    • READY 0/1: readiness probe failing (wrong path/port, app still starting).
    • All replicas restarting or scaled to 0.
    • Maintenance mode or circuit breaker in the proxy/mesh (Envoy "no healthy upstream").

    Diagnose: what each part of the command does

    1. -l app=<app>pods of that app
    2. -o wideshow node and IP too
    Error codes & fixes cheat sheet →
  • curl -sS -o /dev/null -w "connect=%{time_connect}s ttfb=%{time_starttransfer}s total=%{time_total}s\n" <url>504Error codes & fixesGateway Timeout: how long does the backend take?

    What it means

    The gateway did not get a response from the upstream in time.

    Usual causes & fixes

    • Backend slower than the proxy timeout: nginx proxy_read_timeout defaults to 60s; cloud load balancers have their own idle timeout.
    • Slow DB query or external call: check app/DB logs.
    • Network path blocked (security group / firewall) so the connect hangs.

    Diagnose: what each part of the command does

    1. -o /dev/nulldiscard body
    2. %{time_connect}time to open the TCP connection
    3. %{time_starttransfer}time to first byte: how long the backend "thought"
    4. %{time_total}whole request
    Error codes & fixes cheat sheet →
  • echo | openssl s_client -connect <host>:443 -servername <host> 2>/dev/null | openssl x509 -noout -subject -issuer -datesTLSError codes & fixesCertificate expired / not trusted: inspect the cert

    What it means

    Errors like "certificate has expired", "unable to get local issuer certificate" or "hostname mismatch" come from the certificate the server presents.

    Usual causes & fixes

    • Expired: renew (cert-manager / certbot) and reload the server.
    • Missing intermediate chain: serve the full chain (fullchain.pem).
    • Hostname not in the SAN list, or wrong SNI/default certificate.

    Diagnose: what each part of the command does

    1. echo |send an empty request so s_client exits
    2. openssl s_client -connect <host>:443do a TLS handshake
    3. -servername <host>SNI: ask for the certificate of this host name
    4. 2>/dev/nullhide handshake noise
    5. openssl x509 -nooutparse the certificate, do not print it
    6. -subject -issuer -dateswho it is for, who signed it, valid from / until
    Error codes & fixes cheat sheet →
  • echo $?$?Error codes & fixesWhat did the last command return?

    What it means

    Every command returns a number 0-255. 0 means success. CI jobs and && use it.

    Usual causes & fixes

    • Check it right after the command; the next command overwrites it.
    • In scripts use set -e to stop on the first failure, set -o pipefail to catch failures inside pipes.

    Diagnose: what each part of the command does

    1. echoprint
    2. $?exit status of the last command: 0 = success, anything else = failure
    Error codes & fixes cheat sheet →
  • bash -x <script>.sh1Error codes & fixesGeneral error: trace the script

    What it means

    Catch-all for general errors: the program failed and chose 1.

    Usual causes & fixes

    • Read the last lines of stderr: the real message is usually there.
    • A command inside the script failed: -x shows which one.

    Diagnose: what each part of the command does

    1. bashrun the script with bash
    2. -xprint every command (with expanded variables) before running it
    Error codes & fixes cheat sheet →
  • <command> --help2Error codes & fixesMisuse / wrong arguments

    What it means

    Bash builtins return 2 for incorrect usage (invalid option, missing argument); many tools follow this.

    Usual causes & fixes

    • Typo in a flag or a missing required argument.
    • Shell syntax error in a script.

    Diagnose: what each part of the command does

    1. --helpshow valid options and arguments
    Error codes & fixes cheat sheet →
  • ls -l <file>; file <file>126Error codes & fixesFound but cannot execute

    What it means

    The command exists but is not executable.

    Usual causes & fixes

    • Missing execute bit: chmod +x <file>.
    • Windows line endings in a script: sed -i 's/\r$//' <file> (or dos2unix).
    • Filesystem mounted noexec: findmnt -o TARGET,OPTIONS -T <file>.

    Diagnose: what each part of the command does

    1. ls -l <file>check the x permission bit
    2. file <file>check the type: script with CRLF line terminators, wrong binary format…
    Error codes & fixes cheat sheet →
  • command -v <command> || echo "not found; PATH=$PATH"127Error codes & fixesCommand not found

    What it means

    The shell could not find the program in any PATH folder.

    Usual causes & fixes

    • Not installed (install it with apt/dnf/apk).
    • Installed in a folder not on PATH (e.g. ~/.local/bin): export PATH="$HOME/.local/bin:$PATH".
    • Typo, or a container image that does not include the tool (distroless, alpine without bash).

    Diagnose: what each part of the command does

    1. command -v <command>print where the command is, or nothing if it is not found
    2. ||if that failed…
    3. echo "…PATH=$PATH"…show the folders the shell searches
    Error codes & fixes cheat sheet →
  • kill -l $(( <exit-code> - 128 ))128+NError codes & fixesKilled by a signal: which one?

    What it means

    When a process dies from signal N, the shell reports 128+N. E.g. 137 → 9 (KILL), 143 → 15 (TERM), 130 → 2 (INT).

    Usual causes & fixes

    • Run it with the code you got, e.g. kill -l $(( 137 - 128 )) prints KILL.

    Diagnose: what each part of the command does

    1. kill -l <number>print the signal name for a number
    2. $(( … ))shell arithmetic
    3. <exit-code> - 128exit codes above 128 mean "terminated by signal N"
    Error codes & fixes cheat sheet →
  • kill -l 2130Error codes & fixesStopped with Ctrl+C

    What it means

    128 + 2 (SIGINT): someone (or something) pressed Ctrl+C / sent an interrupt.

    Usual causes & fixes

    • Expected if you stopped it. In CI it usually means the job was cancelled.

    Diagnose: what each part of the command does

    1. kill -l 2signal 2 = INT, what Ctrl+C sends
    Error codes & fixes cheat sheet →
  • dmesg -T | grep -i -E "out of memory|killed process"137Error codes & fixesKilled (SIGKILL): usually out of memory

    What it means

    128 + 9 (SIGKILL): the process was force-killed. In containers this is almost always the memory limit (OOMKilled).

    Usual causes & fixes

    • Docker: docker inspect --format '{{.State.OOMKilled}}' <container>; raise -m or fix the leak.
    • Kubernetes: kubectl describe pod <pod> → Last State: Terminated, Reason: OOMKilled; raise resources.limits.memory.
    • A human or script ran kill -9, or a stop timed out and was escalated.

    Diagnose: what each part of the command does

    1. dmesg -Tkernel messages with readable timestamps
    2. grep -i -E "out of memory|killed process"the OOM killer lines
    Error codes & fixes cheat sheet →
  • dmesg -T | grep -i segfault139Error codes & fixesSegmentation fault (SIGSEGV)

    What it means

    128 + 11 (SIGSEGV): the program accessed invalid memory and crashed.

    Usual causes & fixes

    • Bug in a native binary or library; version mismatch between binary and libs (e.g. glibc vs musl/alpine).
    • Wrong CPU architecture image under emulation.

    Diagnose: what each part of the command does

    1. dmesg -Tkernel log
    2. grep -i segfaultlines about the crash (which binary, which library)
    Error codes & fixes cheat sheet →
  • docker inspect --format '{{.State.ExitCode}} {{.State.FinishedAt}}' <container>143Error codes & fixesTerminated (SIGTERM): asked to stop

    What it means

    128 + 15 (SIGTERM): a graceful stop request: docker stop, a Kubernetes rollout/scale-down, systemctl stop.

    Usual causes & fixes

    • Normal during deploys and restarts.
    • If unexpected: check who stopped it (events, kubectl get events, systemd journal).
    • App should handle SIGTERM and exit cleanly within the grace period (terminationGracePeriodSeconds, default 30s).

    Diagnose: what each part of the command does

    1. docker inspectcontainer details
    2. --format '…'print just the exit code and when it stopped
    Error codes & fixes cheat sheet →
  • kubectl logs <pod> -n <namespace> --previousCrashLoopBackOffError codes & fixesContainer keeps crashing: read the crashed run

    What it means

    Not a phase: the container starts, exits, and Kubernetes keeps restarting it with increasing back-off.

    Usual causes & fixes

    • App exits at startup: missing env var, bad config, failed DB connection (see the log).
    • OOMKilled / exit 137: raise the memory limit.
    • Liveness probe kills a slow-starting app: add a startupProbe.
    • Wrong command/args in the pod spec.

    Diagnose: what each part of the command does

    1. logs <pod>container output
    2. --previousfrom the previous (crashed) container, not the one restarting now
    Error codes & fixes cheat sheet →
  • kubectl describe pod <pod> -n <namespace> | grep -A 10 EventsImagePullBackOffError codes & fixesImage cannot be pulled: read the pull error

    What it means

    ErrImagePull / ImagePullBackOff: the kubelet could not pull the image and is backing off.

    Usual causes & fixes

    • Wrong image name or tag (typos, tag never pushed).
    • Private registry without imagePullSecrets.
    • Registry rate limit (Docker Hub "toomanyrequests") or the node cannot reach the registry.
    • Check from your machine: docker pull <image>:<tag>.

    Diagnose: what each part of the command does

    1. describe podfull status
    2. | grep -A 10 Eventsjump to the Events and show 10 lines after
    Error codes & fixes cheat sheet →
  • kubectl describe pod <pod> -n <namespace>PendingError codes & fixesPod not scheduled: why?

    What it means

    The pod is accepted but not running: usually it cannot be scheduled onto any node.

    Usual causes & fixes

    • "Insufficient cpu/memory": requests too high or the cluster is full (scale nodes or lower requests).
    • "had untolerated taint" / node selector or affinity matches no node.
    • PersistentVolumeClaim not bound: kubectl get pvc -n <namespace>.

    Diagnose: what each part of the command does

    1. describe podlook at Events: FailedScheduling explains the reason
    Error codes & fixes cheat sheet →
  • kubectl get configmap,secret -n <namespace>CreateContainerConfigErrorError codes & fixesMissing ConfigMap or Secret

    What it means

    The container config refers to something that does not exist (usually a ConfigMap/Secret or a key in it).

    Usual causes & fixes

    • Create the missing ConfigMap/Secret, or fix the name/key in envFrom / valueFrom.
    • It exists in another namespace: they are namespaced.

    Diagnose: what each part of the command does

    1. get configmap,secretlist both kinds at once
    Error codes & fixes cheat sheet →
  • kubectl get pod <pod> -n <namespace> -o jsonpath='{.status.containerStatuses[*].lastState.terminated.reason}'OOMKilledError codes & fixesWas the container killed for memory?

    What it means

    The container used more memory than its limit and the kernel killed it (exit code 137).

    Usual causes & fixes

    • Raise resources.limits.memory (and requests) or fix the leak; compare with kubectl top pod.
    • JVM/Node.js heap configured larger than the container limit.

    Diagnose: what each part of the command does

    1. -o jsonpath=…print one field
    2. lastState.terminated.reasonwhy the previous container instance ended (OOMKilled, Error, Completed)
    Error codes & fixes cheat sheet →
  • kubectl get pods -A --field-selector=status.phase=FailedEvictedError codes & fixesPods evicted from a node

    What it means

    The kubelet removed pods because the node ran short of memory or disk (or for maintenance).

    Usual causes & fixes

    • Check node pressure: kubectl describe node <node> → Conditions (DiskPressure, MemoryPressure).
    • Clean them up: kubectl delete pods -A --field-selector=status.phase=Failed.
    • Set requests/limits and ephemeral-storage limits so pods are scheduled realistically.

    Diagnose: what each part of the command does

    1. -Aall namespaces
    2. --field-selector=status.phase=Failedevicted pods end up as Failed
    Error codes & fixes cheat sheet →
  • kubectl get events -n <namespace> --sort-by=.lastTimestampContainerCreatingError codes & fixesStuck creating: volume or network problem

    What it means

    The pod is on a node but the container has not started yet.

    Usual causes & fixes

    • FailedMount / FailedAttachVolume: PVC, Secret or ConfigMap volume not available.
    • CNI / network sandbox errors: networking plugin problem on that node.
    • Very large image still pulling.

    Diagnose: what each part of the command does

    1. get eventswhat the scheduler/kubelet reported
    2. --sort-by=.lastTimestampnewest last
    Error codes & fixes cheat sheet →
  • kubectl auth can-i <verb> <resource> -n <namespace> --as=<user>ForbiddenError codes & fixesRBAC: am I allowed to do this?

    What it means

    "… is forbidden: User … cannot …": the identity has no Role/ClusterRole binding for that action.

    Usual causes & fixes

    • Add a RoleBinding / ClusterRoleBinding for the user or service account.
    • Wrong context or namespace: kubectl config current-context.

    Diagnose: what each part of the command does

    1. auth can-iask the API server whether an action is allowed (yes/no)
    2. <verb> <resource>e.g. get pods, create deployments
    3. --as=<user>check for another user or service account (system:serviceaccount:<ns>:<name>)
    Error codes & fixes cheat sheet →
  • kubectl config current-context && kubectl cluster-infoUnable to connectError codes & fixes"Unable to connect to the server" / "Unauthorized"

    What it means

    kubectl cannot reach or authenticate to the API server.

    Usual causes & fixes

    • Wrong context, VPN off, or a private API endpoint.
    • Expired credentials: refresh the kubeconfig (aws eks update-kubeconfig, az aks get-credentials, gcloud container clusters get-credentials).

    Diagnose: what each part of the command does

    1. config current-contextwhich cluster kubectl is pointing at
    2. &&then
    3. cluster-infotry to reach the API server
    Error codes & fixes cheat sheet →
  • namei -l <path>Permission deniedError codes & fixesWhich part of the path blocks me?

    What it means

    The user lacks the permission needed: r to read, w to write, x to run a file or to enter a folder.

    Usual causes & fixes

    • Missing x on a parent folder blocks everything below it.
    • File belongs to another user: sudo chown <user>:<group> <path> or add the user to the group.
    • Script not executable: chmod +x <file>.
    • SELinux/AppArmor can deny even when modes look fine: ls -Z, sudo ausearch -m avc -ts recent.

    Diagnose: what each part of the command does

    1. namei -lowner, group and permissions of every folder on the way to <path>
    Error codes & fixes cheat sheet →
  • df -h <path>; df -i <path>No space left on deviceError codes & fixesOut of disk space or inodes

    What it means

    ENOSPC: the filesystem has no free blocks or no free inodes left.

    Usual causes & fixes

    • Find big folders: sudo du -xh --max-depth=1 <path> | sort -rh | head.
    • Deleted files still open: sudo lsof -nP +L1 (restart the process).
    • Docker: docker system df then prune; journald: journalctl --vacuum-time=7d.

    Diagnose: what each part of the command does

    1. df -h <path>free space on the filesystem holding <path>
    2. df -i <path>free inodes: a disk can be "full" with millions of tiny files
    Error codes & fixes cheat sheet →
  • sudo ss -tlnp | grep :<port>Connection refusedError codes & fixesIs anything listening on that port?

    What it means

    The host answered but nothing accepts connections on that port (or a firewall actively rejects).

    Usual causes & fixes

    • Service not running: systemctl status <service>.
    • Listening only on 127.0.0.1, not 0.0.0.0 / the external IP.
    • Wrong port in the client config.

    Diagnose: what each part of the command does

    1. ss -tlnpTCP listening sockets with numeric ports and process
    2. | grep :<port>only that port
    Error codes & fixes cheat sheet →
  • nc -zv -w 5 <host> <port>Connection timed outError codes & fixesCan I reach the port at all?

    What it means

    No answer at all: packets are dropped on the way.

    Usual causes & fixes

    • Firewall, security group or network ACL blocks the port.
    • Wrong IP / host is down / routing problem (traceroute <host>).

    Diagnose: what each part of the command does

    1. nc -zjust test the connection
    2. -vsay succeeded / timed out
    3. -w 5give up after 5 seconds
    Error codes & fixes cheat sheet →
  • sudo lsof -i :<port>Address already in useError codes & fixesWho holds the port?

    What it means

    EADDRINUSE: another process is already bound to that port.

    Usual causes & fixes

    • Stop the other process or pick another port.
    • Old instance still running (e.g. a previous container: docker ps --filter publish=<port>).

    Diagnose: what each part of the command does

    1. lsof -i :<port>process that has that port open
    Error codes & fixes cheat sheet →
  • getent hosts <hostname>Could not resolve hostError codes & fixesDNS: does the name resolve?

    What it means

    "Name or service not known" / "Temporary failure in name resolution": the hostname could not be turned into an IP.

    Usual causes & fixes

    • Typo, or a private name that only resolves inside a VPN/VPC.
    • Broken resolver: check cat /etc/resolv.conf, test with dig @8.8.8.8 <hostname>.
    • In Kubernetes use <service>.<namespace>.svc.cluster.local.

    Diagnose: what each part of the command does

    1. getent hostsresolve the name the way the system does (/etc/hosts + DNS)
    Error codes & fixes cheat sheet →
  • ulimit -n; grep "open files" /proc/<pid>/limitsToo many open filesError codes & fixesCheck the open-files limit

    What it means

    EMFILE: the process hit its maximum number of open file descriptors.

    Usual causes & fixes

    • Raise it for a service: LimitNOFILE=65536 in the systemd unit, then daemon-reload + restart.
    • A descriptor leak in the app (count them: ls /proc/<pid>/fd | wc -l).

    Diagnose: what each part of the command does

    1. ulimit -nlimit for your current shell
    2. /proc/<pid>/limitsthe limits a running process actually has
    Error codes & fixes cheat sheet →
  • findmnt -o TARGET,OPTIONS -T <path>Read-only file systemError codes & fixesWhy is the disk read-only?

    What it means

    The filesystem is mounted read-only, often remounted by the kernel after disk errors.

    Usual causes & fixes

    • Check kernel errors: dmesg -T | grep -i -E "error|remount".
    • Containers: the image filesystem is read-only by design; write to a volume or /tmp.

    Diagnose: what each part of the command does

    1. findmnt -T <path>the mount that contains <path>
    2. -o TARGET,OPTIONSshow where it is mounted and its options (ro / rw)
    Error codes & fixes cheat sheet →
  • ssh-keygen -R <host>Host key verification failedError codes & fixesServer key changed: remove the old oneCaution

    What it means

    The server's SSH host key differs from the one you saved: a rebuilt server, or a man-in-the-middle.

    Usual causes & fixes

    • Verify the new fingerprint out of band before reconnecting.
    • Expected after recreating a VM with the same IP/name.

    Diagnose: what each part of the command does

    1. ssh-keygen -R <host>delete the saved key for <host> from ~/.ssh/known_hosts
    Error codes & fixes cheat sheet →
  • ssh -v <user>@<host>Permission denied (publickey)Error codes & fixesSSH key rejected: see what ssh tries

    What it means

    The server did not accept any of your keys.

    Usual causes & fixes

    • Wrong user (ubuntu vs ec2-user vs root) or wrong key: ssh -i <key-file> <user>@<host>.
    • Permissions too open: chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys ~/.ssh/id_ed25519 (sshd StrictModes refuses group/world-writable files).
    • Public key not in the server's ~/.ssh/authorized_keys: ssh-copy-id <user>@<host>.

    Diagnose: what each part of the command does

    1. -vverbose: shows which keys are offered and why they are refused
    Error codes & fixes cheat sheet →
  • sudo usermod -aG docker $USER && newgrp dockerdocker.sock permission deniedError codes & fixes"permission denied while trying to connect to the Docker daemon socket"Caution

    What it means

    Your user may not talk to /var/run/docker.sock.

    Usual causes & fixes

    • Note: the docker group is root-equivalent on that machine.

    Diagnose: what each part of the command does

    1. usermod -aG docker $USERadd yourself to the docker group
    2. &&then
    3. newgrp dockerstart a shell with the new group (or log out and in)
    Error codes & fixes cheat sheet →
  • sudo systemctl status dockerCannot connect to daemonError codes & fixes"Cannot connect to the Docker daemon … Is the docker daemon running?"

    What it means

    The client cannot reach dockerd.

    Usual causes & fixes

    • Start it: sudo systemctl enable --now docker.
    • Wrong DOCKER_HOST or context: docker context ls.

    Diagnose: what each part of the command does

    1. systemctl status dockeris the Docker service running, and its last log lines
    Error codes & fixes cheat sheet →
  • docker ps --filter publish=<port>port is already allocatedError codes & fixesWhich container holds the host port?

    What it means

    Another container (or process) already uses that host port.

    Usual causes & fixes

    • Stop/remove the other container, or map a different host port (-p 8081:80).
    • Not a container? sudo lsof -i :<port>.

    Diagnose: what each part of the command does

    1. --filter publish=<port>containers publishing that host port
    Error codes & fixes cheat sheet →
  • docker image inspect <image> --format '{{.Os}}/{{.Architecture}}'exec format errorError codes & fixesImage built for another CPU architecture

    What it means

    The binary in the image does not match the machine's CPU (e.g. an arm64 image on amd64), or a script lacks a shebang.

    Usual causes & fixes

    • Build for the target: docker buildx build --platform linux/amd64,linux/arm64 ….
    • Script entrypoint: add #!/bin/sh as the first line.

    Diagnose: what each part of the command does

    1. image inspectimage metadata
    2. --format '{{.Os}}/{{.Architecture}}'e.g. linux/arm64 vs linux/amd64
    Error codes & fixes cheat sheet →
  • docker logintoomanyrequestsError codes & fixesDocker Hub pull rate limit

    What it means

    Anonymous pulls from Docker Hub are rate-limited per IP.

    Usual causes & fixes

    • Log in (also on CI runners / nodes via imagePullSecrets).
    • Use a pull-through cache or mirror the images to your own registry.

    Diagnose: what each part of the command does

    1. docker loginauthenticated pulls get a higher limit
    Error codes & fixes cheat sheet →
  • git pull --rebase origin <branch>rejected (non-fast-forward)Error codes & fixes"Updates were rejected because the remote contains work that you do not have"

    What it means

    Someone pushed to the branch since you last pulled; a plain push would overwrite their work.

    Usual causes & fixes

    • Pull with rebase, resolve conflicts, then git push.
    • Only after a deliberate rebase of your own branch: git push --force-with-lease.

    Diagnose: what each part of the command does

    1. pull --rebasefetch the remote commits and replay yours on top
    2. origin <branch>the branch you are pushing
    Error codes & fixes cheat sheet →
  • git diff --name-only --diff-filter=UCONFLICTError codes & fixesMerge conflict: which files?

    What it means

    Both sides changed the same lines; Git marked them with <<<<<<< ======= >>>>>>>.

    Usual causes & fixes

    • Edit the files, remove the markers, git add <file>, then git commit (or git rebase --continue).
    • Give up: git merge --abort / git rebase --abort.

    Diagnose: what each part of the command does

    1. --name-onlylist file names only
    2. --diff-filter=Uonly Unmerged (conflicted) files
    Error codes & fixes cheat sheet →
  • git switch -c <new-branch>detached HEADError codes & fixesKeep work done in detached HEAD

    What it means

    You checked out a commit or tag directly, not a branch. New commits belong to no branch.

    Usual causes & fixes

    • Already switched away? Find the commit in git reflog.

    Diagnose: what each part of the command does

    1. switch -c <new-branch>create a branch at the current commit so the work is not lost
    Error codes & fixes cheat sheet →
  • git rev-parse --show-toplevelnot a git repositoryError codes & fixes"fatal: not a git repository"

    What it means

    The current folder is not inside a Git working tree.

    Usual causes & fixes

    • cd into the repo, or git init / git clone first.
    • In CI/containers: "dubious ownership" → git config --global --add safe.directory <path>.

    Diagnose: what each part of the command does

    1. rev-parse --show-toplevelprint the repo root, or fail if you are not inside a repo
    Error codes & fixes cheat sheet →
  • terraform force-unlock <lock-id>state lockError codes & fixesTerraform "Error acquiring the state lock"Destructive

    What it means

    Another run holds the state lock, or a crashed/cancelled run left it behind.

    Usual causes & fixes

    • Make sure no other plan/apply is running first.
    • Avoid by not cancelling apply jobs; use a CI concurrency group per workspace.

    Diagnose: what each part of the command does

    1. force-unlock <lock-id>remove the lock (ID is in the error message)
    Error codes & fixes cheat sheet →
  • helm history <release> -n <namespace>another operation in progressError codes & fixesHelm "another operation (install/upgrade/rollback) is in progress"

    What it means

    A previous Helm operation was interrupted and left the release in a pending state.

    Usual causes & fixes

    • Roll back to the last deployed revision: helm rollback <release> <revision> -n <namespace>.
    • Use --rollback-on-failure (Helm 4) / --atomic (Helm 3) and a timeout so this cleans up itself.

    Diagnose: what each part of the command does

    1. history <release>revisions; the last one is stuck in pending-install / pending-upgrade
    Error codes & fixes cheat sheet →

Shell basics: help, variables, pipes & chaining25

  • man <command>Linux & shellRead the manual for a command

    What each part does

    1. manmanual page; / to search, q to quit
    2. <command>e.g. man ls, man tar
    Linux & shell cheat sheet →
  • <command> --helpLinux & shellQuick help for a command

    What each part does

    1. --helpmost tools print their options and exit
    Linux & shell cheat sheet →
  • which <command>; type <command>Linux & shellWhere is a command installed?

    What each part does

    1. whichpath of the program that would run
    2. typealso tells you if it is an alias, built-in or function
    Linux & shell cheat sheet →
  • history | grep <word>Linux & shellSearch your command history

    What each part does

    1. historynumbered list of commands you ran
    2. | grep <word>only the ones containing <word>; re-run one with !<number>

    Tip Faster: press Ctrl+R and start typing to search history interactively.

    Linux & shell cheat sheet →
  • sudo !!Linux & shellRe-run the last command with sudo

    What each part does

    1. sudorun as root
    2. !!history expansion: the whole previous command
    Linux & shell cheat sheet →
  • alias ll='ls -lh'Linux & shellCreate a shortcut command

    What each part does

    1. aliasdefine a short name for a command
    2. ll='ls -lh'typing ll now runs ls -lh (add it to ~/.bashrc to keep it)
    Linux & shell cheat sheet →
  • echo "$HOME"Linux & shellPrint a variable

    What each part does

    1. echoprint text
    2. "$HOME"value of the HOME variable; quotes keep spaces intact
    Linux & shell cheat sheet →
  • export <NAME>=<value>Linux & shellSet a variable for this shell and its programs

    What each part does

    1. exportmake the variable visible to programs you start from this shell
    2. <NAME>=<value>no spaces around =
    Linux & shell cheat sheet →
  • env | grep <NAME>Linux & shellShow environment variables

    What each part does

    1. envall environment variables
    2. | grep <NAME>only matching ones
    Linux & shell cheat sheet →
  • sudo <command>; sudo -iLinux & shellRun as root / open a root shellCaution

    What each part does

    1. sudo <command>run one command as root (asks for your password)
    2. sudo -iinteractive root login shell; type exit to leave
    Linux & shell cheat sheet →
  • Tab · Ctrl+C · Ctrl+R · Ctrl+L · Ctrl+DLinux & shellUseful keys

    What each part does

    1. Tabcomplete file and command names (press twice to list options)
    2. Ctrl+Cstop the running command
    3. Ctrl+Rsearch command history
    4. Ctrl+Lclear the screen (same as clear)
    5. Ctrl+Dend input / log out of the shell
    Linux & shell cheat sheet →
  • cmd1 | cmd2Linux & shellSend the output of one command into another

    What each part does

    1. cmd1first command; its normal output (stdout) is captured
    2. |pipe: stdout of the left command becomes the input (stdin) of the right one
    3. cmd2second command, reads that input (e.g. grep, sort, head)
    Linux & shell cheat sheet →
  • cmd > out.txt; cmd >> out.txtLinux & shellSave output to a file (overwrite / append)

    What each part does

    1. >redirect stdout to a file, creating it or truncating it to empty first
    2. ;run the next command after the first, whatever its result
    3. >>append stdout to the end of the file (creates it if missing)
    Linux & shell cheat sheet →
  • cmd > out.log 2>&1Linux & shellCapture errors together with normal output

    What each part does

    1. > out.logstdout (file descriptor 1) goes to out.log
    2. 2>&1make stderr (fd 2) point where stdout points. Order matters: it must come after > out.log

    Tip Short bash form: cmd &> out.log

    Linux & shell cheat sheet →
  • make build && make deploy || echo "failed"Linux & shellRun the next command only if the previous one succeeded / failed

    What each part does

    1. make buildfirst command
    2. &&run the next command only if the previous exited with code 0 (success)
    3. make deployruns only after a successful build
    4. ||run the next command only if the previous exited non-zero (failure)
    5. echo "failed"fallback message
    Linux & shell cheat sheet →
  • kill $(pgrep -f <name>)Linux & shellUse the output of a command as an argument

    What each part does

    1. killsend a signal (TERM by default) to process IDs
    2. $( … )command substitution: run the inner command and paste its output here
    3. pgrep -f <name>print PIDs whose full command line matches <name>
    Linux & shell cheat sheet →
  • cat <list-file> | xargs -r -n 1 <cmd>Linux & shellPass input lines as arguments to another command

    What each part does

    1. cat <list-file>print the file (one item per line)
    2. |pipe into xargs
    3. xargsbuild and run command lines from its input
    4. -rdon't run the command at all if the input is empty (GNU xargs)
    5. -n 1one input item per command invocation
    6. <cmd>the command to run with each item appended
    Linux & shell cheat sheet →
  • tmux new -A -s <name>Linux & shellStart or reattach a tmux session

    What each part does

    1. tmux new -s <name>new named session that survives SSH disconnects
    2. -Aattach instead if it already exists

    Tip Detach with Ctrl+B then D; list with tmux ls.

    Linux & shell cheat sheet →
  • <command> | jq '.items[] | {name: .metadata.name, phase: .status.phase}'Linux & shellPretty-print and filter JSON

    What each part does

    1. | jq '...'JSON processor
    2. .items[]iterate over an array
    3. {name: ..., phase: ...}build a smaller object with just those fields
    Linux & shell cheat sheet →
  • jq -r '.[] | select(.state=="running") | .name' <file>.jsonLinux & shellRaw values from JSON for scripts

    What each part does

    1. -rraw strings, no quotes
    2. select(.state=="running")keep only matching items
    3. .nameprint one field
    Linux & shell cheat sheet →
  • yq '.spec.replicas' <file>.yaml; yq -i '.spec.replicas = 3' <file>.yamlLinux & shellRead or edit YAML

    What each part does

    1. yq '.path'read a value (jq syntax for YAML)
    2. yq -i '...'edit the file in place
    Linux & shell cheat sheet →
  • nohup <command> > <log> 2>&1 &Linux & shellKeep a command running after logout

    What each part does

    1. nohupignore the hangup signal sent when you log out
    2. > <log> 2>&1send output and errors to a log
    3. &run in the background; jobs and fg to manage it
    Linux & shell cheat sheet →
  • timeout 30s <command>Linux & shellStop a command that runs too long

    What each part does

    1. timeout 30skill the command after 30 seconds; exit code 124 if it timed out
    Linux & shell cheat sheet →
  • cat <list> | xargs -P 8 -I{} <command> {}Linux & shellRun commands in parallel

    What each part does

    1. xargs -P 8up to 8 at a time
    2. -I{}replace {} in the command with each input line
    Linux & shell cheat sheet →
  • until <command>; do echo retrying; sleep 5; doneLinux & shellRetry a command until it succeeds

    What each part does

    1. until <command>loop while the command fails
    2. sleep 5wait between attempts
    Linux & shell cheat sheet →

Everyday basics: Docker, Kubernetes, Git51

  • docker version; docker infoDockerIs Docker installed and running?

    What each part does

    1. docker versionclient and server (daemon) versions; an error on Server means the daemon is not running
    2. docker infosystem-wide details: containers, images, storage driver, cgroup driver
    Docker cheat sheet →
  • docker run --rm hello-worldDockerTest that everything works

    What each part does

    1. docker runcreate and start a container (pulls the image if missing)
    2. --rmremove the container when it exits
    3. hello-worldtiny test image that prints a greeting
    Docker cheat sheet →
  • docker imagesDockerList local images

    What each part does

    1. docker imagesalias of docker image ls: repository, tag, image ID, size
    Docker cheat sheet →
  • docker pull <image>:<tag>DockerDownload an image

    What each part does

    1. docker pulldownload from a registry (Docker Hub by default)
    2. <image>:<tag>e.g. nginx:1.27; without a tag it means :latest
    Docker cheat sheet →
  • docker ps; docker ps -aDockerList running / all containers

    What each part does

    1. docker psrunning containers
    2. -ainclude stopped ones
    Docker cheat sheet →
  • docker start <container>; docker stop <container>; docker restart <container>DockerStart, stop, restart a container

    What each part does

    1. startstart a stopped container (keeps its data and settings)
    2. stopgraceful stop: SIGTERM, then SIGKILL after 10s (-t to change)
    3. restartstop then start
    Docker cheat sheet →
  • docker rm <container>DockerRemove a containerCaution

    What each part does

    1. docker rmdelete a stopped container; add -f to stop and delete a running one
    Docker cheat sheet →
  • docker rmi <image>:<tag>DockerRemove an imageCaution

    What each part does

    1. docker rmidelete a local image; -f forces it even if tagged elsewhere
    Docker cheat sheet →
  • docker rename <old-name> <new-name>DockerRename a container

    What each part does

    1. docker renamechange the container name
    Docker cheat sheet →
  • docker port <container>DockerWhich host port maps to the container?

    What each part does

    1. docker portlist port mappings, e.g. 80/tcp -> 0.0.0.0:8080
    Docker cheat sheet →
  • docker login <registry>; docker logout <registry>DockerLog in / out of a registry

    What each part does

    1. docker loginstore credentials (Docker Hub if no registry is given)
    2. docker logoutremove them
    Docker cheat sheet →
  • kubectl versionKubernetesClient and cluster version

    What each part does

    1. kubectl versionclient and server versions; add --client for the client only (no cluster needed)
    Kubernetes cheat sheet →
  • kubectl cluster-infoKubernetesIs the cluster reachable?

    What each part does

    1. cluster-infoaddresses of the control plane and core services
    Kubernetes cheat sheet →
  • kubectl get nodes -o wideKubernetesList nodes

    What each part does

    1. get nodescluster nodes and whether they are Ready
    2. -o wideadd internal/external IP, OS, kernel, container runtime
    Kubernetes cheat sheet →
  • kubectl get nsKubernetesList namespaces

    What each part does

    1. get nsshort for get namespaces
    Kubernetes cheat sheet →
  • kubectl create namespace <namespace>KubernetesCreate a namespace

    What each part does

    1. create namespacemake a new namespace (short: create ns)
    Kubernetes cheat sheet →
  • kubectl get all -n <namespace>KubernetesEverything in a namespace

    What each part does

    1. get allpods, services, deployments, replicasets, statefulsets, jobs… (not configmaps/secrets/ingress)
    2. -n <namespace>--namespace: which namespace
    Kubernetes cheat sheet →
  • kubectl get deploy,svc,ing -n <namespace>KubernetesDeployments, services and ingresses at once

    What each part does

    1. deploy,svc,ingcomma-separated resource types (short names)
    Kubernetes cheat sheet →
  • kubectl get configmap,secret -n <namespace>KubernetesConfigMaps and Secrets

    What each part does

    1. configmap,secretconfig objects (secret values are not shown here)
    Kubernetes cheat sheet →
  • kubectl get pods -wKubernetesWatch pods change live

    What each part does

    1. -w--watch: keep printing updates until Ctrl+C
    Kubernetes cheat sheet →
  • kubectl get pod <pod> -o yamlKubernetesFull YAML of a live object

    What each part does

    1. -o yamloutput the whole object, including status
    Kubernetes cheat sheet →
  • kubectl apply -f <file-or-dir>KubernetesCreate / update from a file

    What each part does

    1. applycreate or update to match the manifest
    2. -f--filename: a file, a folder or a URL (add -R for sub-folders)
    Kubernetes cheat sheet →
  • kubectl delete -f <file-or-dir>KubernetesDelete what a file definesDestructive

    What each part does

    1. delete -fdelete the objects listed in the manifest
    Kubernetes cheat sheet →
  • kubectl edit deploy/<deployment>KubernetesEdit a live object in your editorCaution

    What each part does

    1. editopens the object in $EDITOR (KUBE_EDITOR); saving applies it
    Kubernetes cheat sheet →
  • kubectl label pod <pod> <key>=<value> --overwriteKubernetesAdd or change a label

    What each part does

    1. labelset labels on objects
    2. <key>=<value>the label; <key>- (trailing dash) removes it
    3. --overwriteallow replacing an existing value
    Kubernetes cheat sheet →
  • kubectl expose deployment <deployment> --port=80 --target-port=8080 --type=ClusterIPKubernetesExpose a deployment as a service

    What each part does

    1. exposecreate a Service for a workload
    2. --port=80port the Service listens on
    3. --target-port=8080container port the traffic goes to
    4. --type=ClusterIPClusterIP (default, in-cluster), NodePort or LoadBalancer
    Kubernetes cheat sheet →
  • kubectl run tmp --rm -it --restart=Never --image=busybox:1.36 -- shKubernetesThrow-away debug pod with a shell

    What each part does

    1. run tmpcreate a pod named tmp
    2. --rmdelete it when you exit
    3. -itinteractive terminal
    4. --restart=Nevera plain pod, not managed by anything
    5. --image=busybox:1.36small image with basic tools (nslookup, wget)
    6. -- shcommand to run
    Kubernetes cheat sheet →
  • kubectl get secret <secret> -o jsonpath='{.data.<key>}' | base64 -dKubernetesRead one value from a SecretCaution

    What each part does

    1. -o jsonpath=…print just that field
    2. {.data.<key>}the base64-encoded value of <key>
    3. | base64 -ddecode it to plain text

    Tip Prints a secret to your terminal.

    Kubernetes cheat sheet →
  • git config --global user.name "<name>"; git config --global user.email "<email>"GitSet your name and email (once per machine)

    What each part does

    1. git configread/write Git settings
    2. --globalfor your user (~/.gitconfig), all repos
    3. user.name / user.emailrecorded as the author of your commits

    Tip Git 2.46+ also has: git config set --global user.name "<name>". Check with git config list --show-origin.

    Git cheat sheet →
  • git init -b mainGitStart a new repo

    What each part does

    1. initcreate a .git folder here
    2. -b main--initial-branch: name the first branch main
    Git cheat sheet →
  • git clone <url>GitCopy a remote repo

    What each part does

    1. clone <url>download the repo with full history into a new folder
    Git cheat sheet →
  • git clone --depth 1 <url>GitShallow clone (fast, latest commit only)

    What each part does

    1. --depth 1only the most recent commit, no history
    Git cheat sheet →
  • git statusGitWhat changed?

    What each part does

    1. statusbranch, staged, not-staged and untracked files
    Git cheat sheet →
  • git add <file>; git add -AGitStage one file / everything

    What each part does

    1. add <file>stage that file for the next commit
    2. add -A--all: stage every change in the repo, including deletions (git add . = only under the current folder)
    Git cheat sheet →
  • git add -pGitStage only parts of a file

    What each part does

    1. -p--patch: go through each change and choose y/n
    Git cheat sheet →
  • git commit -m "<message>"GitCommit staged changes

    What each part does

    1. commitrecord the staged changes
    2. -m "<message>"commit message (without -m an editor opens)
    Git cheat sheet →
  • git commit -am "<message>"GitStage tracked files and commit in one step

    What each part does

    1. -a--all: auto-stage modified and deleted tracked files (NOT new files)
    2. -mmessage
    Git cheat sheet →
  • git commit --amend --no-editGitFix the last commit (not pushed yet)Caution

    What each part does

    1. --amendreplace the last commit with one that includes what is staged now
    2. --no-editkeep the same message
    Git cheat sheet →
  • git log --oneline -n 10GitRecent history

    What each part does

    1. --onelineone line per commit
    2. -n 10only the last 10
    Git cheat sheet →
  • git diff; git diff --stagedGitSee the changes

    What each part does

    1. git diffchanges not staged yet
    2. --stagedwhat is staged (alias --cached)
    Git cheat sheet →
  • git show <commit>GitShow one commit

    What each part does

    1. showmessage, author and diff of that commit (HEAD if omitted)
    Git cheat sheet →
  • git branch -aGitList branches

    What each part does

    1. -a--all: local and remote-tracking branches; * marks the current one
    Git cheat sheet →
  • git checkout -b <branch>GitCreate and switch to a branch

    What each part does

    1. checkout -bolder equivalent of git switch -c
    Git cheat sheet →
  • git branch -d <branch>; git branch -D <branch>GitDelete a branchCaution

    What each part does

    1. -ddelete if it is fully merged
    2. -Dforce delete even if not merged
    Git cheat sheet →
  • git merge --no-ff <branch>GitMerge a branch into the current one

    What each part does

    1. merge <branch>bring <branch>'s commits into the current branch
    2. --no-ffalways create a merge commit, even when a fast-forward is possible

    Tip Conflict? Fix the files, git add them, git commit, or give up with git merge --abort.

    Git cheat sheet →
  • git remote -vGitWhich remotes are set up?

    What each part does

    1. -vshow fetch and push URLs
    Git cheat sheet →
  • git remote add origin <url>GitAdd a remote

    What each part does

    1. remote add origin <url>name the remote "origin" (convention)
    Git cheat sheet →
  • git pullGitGet the latest from the remote

    What each part does

    1. pullfetch + merge the upstream branch (git pull --rebase to rebase instead)
    Git cheat sheet →
  • git pushGitUpload your commits

    What each part does

    1. pushsend commits to the upstream branch (first time: git push -u origin <branch>)
    Git cheat sheet →
  • git rm --cached <file>GitStop tracking a file but keep it on disk

    What each part does

    1. rmremove from Git
    2. --cachedonly from the index; the file stays (then add it to .gitignore)
    Git cheat sheet →
  • git mv <old> <new>GitRename a tracked file

    What each part does

    1. git mvrename and stage the rename in one step
    Git cheat sheet →

Permissions & ownership (chmod, chown, ACL)31

  • ls -l <file>Linux & shellRead a permission string

    What it means

    On a directory: r = list names, w = create/delete entries, x = enter it / reach things inside.

    What each part does

    1. -rwxr-xr-xexample output; 1st char is the type: - file, d directory, l symlink
    2. rwxchars 2-4, owner (user): r read, w write, x execute
    3. r-xchars 5-7, group: - means "not allowed"
    4. r-xchars 8-10, others (everyone else)
    5. s / ts in an x slot = setuid/setgid, t in the last slot = sticky (capital S/T = bit set but no x)
    6. +a trailing + means extra ACL entries exist (see getfacl)
    Linux & shell cheat sheet →
  • stat -c '%a %A %U:%G %n' <file>Linux & shellSee permissions as numbers

    What each part does

    1. stat -cprint chosen fields
    2. %apermissions in octal, e.g. 755
    3. %Athe same as letters, e.g. -rwxr-xr-x
    4. %U:%Gowner user and group
    5. %nfile name
    Linux & shell cheat sheet →
  • chmod 755 <file-or-dir>Linux & shellOctal modes explained: 755

    What each part does

    1. chmodchange mode (permissions)
    2. 7owner = 4 read + 2 write + 1 execute = rwx
    3. 5group = 4 read + 1 execute = r-x
    4. 5others = r-x

    Tip Typical for folders, scripts and binaries.

    Linux & shell cheat sheet →
  • chmod 644 <file>Linux & shellRegular files: owner writes, everyone reads

    What each part does

    1. 6owner rw- (4+2)
    2. 4group r--
    3. 4others r--

    Tip Typical for config files, web content, documents.

    Linux & shell cheat sheet →
  • chmod 600 <file>Linux & shellPrivate file: only the owner

    What each part does

    1. 6owner rw-
    2. 0group: nothing
    3. 0others: nothing

    Tip Use for secrets: .env files, private keys, kubeconfig, credentials.

    Linux & shell cheat sheet →
  • chmod 700 <dir>Linux & shellPrivate folder / script: only the owner

    What each part does

    1. 7owner rwx
    2. 0 0group and others: no access at all
    Linux & shell cheat sheet →
  • chmod 750 <dir>; chmod 640 <file>Linux & shellShared with the group, hidden from others

    What each part does

    1. 750dir: owner rwx, group r-x (can enter and read), others none
    2. 640file: owner rw-, group r--, others none
    Linux & shell cheat sheet →
  • chmod 400 <file>Linux & shellRead-only for the owner

    What each part does

    1. 4owner r-- only
    2. 00nobody else

    Tip AWS .pem key files are expected to be 400 or 600.

    Linux & shell cheat sheet →
  • chmod 777 <path>Linux & shell777: everyone can do everything (avoid)Destructive

    What each part does

    1. 7 7 7rwx for owner, group and ALL other users

    Tip Any user or compromised process can change or replace the file, or delete files in the folder. Fix ownership or group instead (chown / chgrp + 775 or 770).

    Linux & shell cheat sheet →
  • chmod +x <script>.sh && ./<script>.shLinux & shellMake a script executable and run it

    What each part does

    1. +xadd execute (no who-letter = for all, minus the umask bits)
    2. &&then
    3. ./<script>.shrun it from the current folder (. is not on PATH)
    Linux & shell cheat sheet →
  • chmod u+x,g-w,o-rwx <file>Linux & shellSymbolic: add or remove for owner/group/others

    What each part does

    1. u+xu = owner (user): add execute
    2. ,separate clauses
    3. g-wg = group: remove write
    4. o-rwxo = others: remove everything

    Tip Who: u, g, o, a (all). Operator: + add, - remove, = set exactly. Perms: r w x X s t.

    Linux & shell cheat sheet →
  • chmod u=rwx,go=rx <path>Linux & shellSymbolic: set exact permissions

    What each part does

    1. u=rwxowner gets exactly rwx
    2. go=rxgroup and others get exactly r-x (same as 755)
    Linux & shell cheat sheet →
  • chmod a+r <file>Linux & shellGive everyone read access

    What each part does

    1. a+ra = all (owner, group, others): add read
    Linux & shell cheat sheet →
  • chmod -R u+rwX,go+rX,go-w <dir>Linux & shellRecursive, the safe way (capital X)

    What each part does

    1. -R--recursive: the folder and everything inside
    2. u+rwXowner: read, write, and execute only for folders / files already executable
    3. go+rXgroup/others: read, and enter folders
    4. go-wgroup/others: no write

    Tip X (capital) avoids making every plain file executable, which chmod -R 755 would do.

    Linux & shell cheat sheet →
  • find <dir> -type d -exec chmod 755 {} + && find <dir> -type f -exec chmod 644 {} +Linux & shellFolders 755, files 644 (fix a messy tree)Caution

    What each part does

    1. find <dir> -type devery directory under <dir>
    2. -exec chmod 755 {} +run chmod on them in batches ({} = the found names)
    3. &&then
    4. -type f … chmod 644every regular file gets 644

    Tip Re-add +x afterwards to scripts that need it.

    Linux & shell cheat sheet →
  • chmod --reference=<source-file> <file>Linux & shellCopy permissions from another file

    What each part does

    1. --reference=<source-file>use that file's mode instead of typing one
    Linux & shell cheat sheet →
  • sudo chown <user> <path>Linux & shellChange the owner

    What each part does

    1. chown <user>new owner; the group stays the same
    Linux & shell cheat sheet →
  • sudo chown -R <user>:<group> <path>Linux & shellChange owner and group, recursively

    What each part does

    1. -Rrecursive
    2. <user>:<group>both at once (no spaces). <user>: alone = also set the user's login group
    Linux & shell cheat sheet →
  • sudo chgrp -R <group> <path>Linux & shellChange only the group

    What each part does

    1. chgrpchange group (same as chown :<group>)
    2. -Rrecursive
    Linux & shell cheat sheet →
  • sudo chown -R --from=<old-user> <new-user> <dir>Linux & shellRe-own only files that belong to someone else

    What each part does

    1. --from=<old-user>change only files currently owned by <old-user>
    2. <new-user>new owner
    Linux & shell cheat sheet →
  • sudo chgrp <group> <dir> && sudo chmod 2775 <dir>Linux & shellShared team folder: new files keep the folder group

    What each part does

    1. chgrp <group> <dir>folder belongs to the team group
    2. 2setgid bit: new files/folders inside inherit the folder's group
    3. 775owner and group rwx, others r-x

    Tip Symbolic form: chmod g+s <dir>.

    Linux & shell cheat sheet →
  • sudo chmod 1777 <dir>Linux & shellSticky folder: users can only delete their own files

    What each part does

    1. 1sticky bit: only the file owner (or dir owner/root) can delete or rename entries
    2. 777everyone can create files

    Tip This is how /tmp is set up (drwxrwxrwt). Symbolic: chmod +t <dir>.

    Linux & shell cheat sheet →
  • sudo find / -xdev -type f -perm /4000 2>/dev/nullLinux & shellFind setuid programs (security audit)

    What each part does

    1. -xdevstay on one filesystem
    2. -type ffiles only
    3. -perm /4000any file with the setuid bit (runs as its owner, often root)
    4. 2>/dev/nullhide "Permission denied" noise
    Linux & shell cheat sheet →
  • find <dir> -type f -perm -o+wLinux & shellFind world-writable files

    What each part does

    1. -perm -o+w"-" = all listed bits must be set: others have write
    Linux & shell cheat sheet →
  • umask; umask 027Linux & shellDefault permissions for new files (umask)

    What each part does

    1. umaskshow the current mask (usually 0022)
    2. umask 027set it for this shell: bits in the mask are REMOVED from new files

    Tip New files start from 666, folders from 777. 022 → files 644, dirs 755. 027 → 640 / 750. 077 → 600 / 700. Put it in ~/.bashrc or the service unit (UMask=) to keep it.

    Linux & shell cheat sheet →
  • setfacl -m u:<user>:rwx <path>Linux & shellGive one extra user access (ACL)

    What each part does

    1. setfaclset file access control lists
    2. -m--modify: add or change an entry
    3. u:<user>:rwxentry: u = user, then the name, then permissions (g:<group>:rx for a group)
    Linux & shell cheat sheet →
  • setfacl -R -m u:<user>:rwX <dir> && setfacl -d -m u:<user>:rwX <dir>Linux & shellACL for everything inside, and for future files

    What each part does

    1. -Rapply to existing files recursively
    2. -d--default: entries that NEW files and folders inside will inherit
    3. rwXX = execute only on folders/executables
    Linux & shell cheat sheet →
  • getfacl <path>Linux & shellShow ACLs

    What each part does

    1. getfaclowner, group, and every ACL entry with its effective rights (mask applies)
    Linux & shell cheat sheet →
  • setfacl -x u:<user> <path>; setfacl -b <path>Linux & shellRemove ACL entries

    What each part does

    1. -x u:<user>remove that user's entry (no permissions in the spec)
    2. -b--remove-all: drop every extra entry, keep owner/group/others
    Linux & shell cheat sheet →
  • chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys ~/.ssh/id_ed25519Linux & shellSSH files: fix permissions so sshd accepts them

    What each part does

    1. 700 ~/.sshonly you can enter or list the folder
    2. 600 authorized_keysonly you can read/write the list of allowed keys
    3. 600 id_ed25519private key readable only by you (public .pub can be 644)

    Tip With StrictModes (default yes) sshd refuses keys if these are group/world-writable.

    Linux & shell cheat sheet →
  • namei -l <path>Linux & shellWhy is access denied? Check every folder on the path

    What each part does

    1. namei -llist owner, group and mode of each component: missing x on any parent blocks access
    Linux & shell cheat sheet →

Users & groups6

  • whoami; idLinux & shellWho am I?

    What each part does

    1. whoamiyour user name
    2. idyour user ID, primary group and all groups
    Linux & shell cheat sheet →
  • groups <user>Linux & shellWhich groups is a user in?

    What each part does

    1. groupslist group memberships (yours if no user given)
    Linux & shell cheat sheet →
  • su - <user>Linux & shellSwitch to another user

    What each part does

    1. susubstitute user
    2. -start a full login shell (their home folder and environment)
    Linux & shell cheat sheet →
  • sudo useradd -m -s /bin/bash <user>Linux & shellCreate a user with a home folder and bash

    What each part does

    1. useraddcreate a user account
    2. -m--create-home: create /home/<user> with the skeleton files
    3. -s /bin/bash--shell: login shell
    Linux & shell cheat sheet →
  • sudo usermod -aG <group> <user>Linux & shellAdd a user to a group (keep other groups)

    What each part does

    1. usermodmodify a user
    2. -a--append: add to the group (only valid with -G)
    3. -G <group>supplementary group(s). Without -a the user is REMOVED from groups not listed

    Tip Typical: sudo usermod -aG docker $USER, then log out and in again.

    Linux & shell cheat sheet →
  • sudo passwd <user>Linux & shellSet or change a password

    What each part does

    1. passwdchange the password (your own if no user given, no sudo needed)
    Linux & shell cheat sheet →

Install packages36

  • sudo apt update && sudo apt upgrade -yLinux & shellRefresh package lists and upgrade (Debian/Ubuntu)

    What each part does

    1. apt updatedownload the latest package lists (installs nothing)
    2. &&only if that worked
    3. apt upgradeinstall newer versions of installed packages
    4. -yanswer yes to the prompt
    Linux & shell cheat sheet →
  • sudo apt install -y <package>Linux & shellInstall a package

    What each part does

    1. apt installinstall a package and its dependencies
    2. -yno confirmation prompt
    Linux & shell cheat sheet →
  • sudo apt remove <package>Linux & shellRemove a packageCaution

    What each part does

    1. apt removeuninstall (keeps config files; apt purge removes those too)
    Linux & shell cheat sheet →
  • apt search <word>Linux & shellFind a package

    What each part does

    1. apt searchsearch package names and descriptions
    Linux & shell cheat sheet →
  • apt list --installed | grep <package>Linux & shellIs it installed?

    What each part does

    1. apt list --installedevery installed package
    2. | grep <package>filter to the one you want
    Linux & shell cheat sheet →
  • sudo dnf install -y <package>Linux & shellInstall on RHEL / Fedora / Amazon Linux

    What each part does

    1. dnf installinstall with the dnf package manager (yum on older systems)
    2. -yno prompt
    Linux & shell cheat sheet →
  • apk add --no-cache <package>Linux & shellInstall on Alpine (common in containers)

    What each part does

    1. apk addAlpine's package manager
    2. --no-cachedon't keep the package index: smaller images
    Linux & shell cheat sheet →
  • hostnamectlLinux & shellOS, version and kernel in one view

    What each part does

    1. hostnamectlhostname, operating system and version, kernel, architecture, virtualization (systemd systems)
    Linux & shell cheat sheet →
  • <program> --versionLinux & shellVersion of any program

    What each part does

    1. <program> --versionmost tools print their version; some use -v or -V (nginx -v, java -version, python3 -V)
    Linux & shell cheat sheet →
  • dpkg -S "$(command -v <program>)"Linux & shellWhere is a command, and which package installed it? (Debian / Ubuntu)

    What each part does

    1. command -v <program>full path of the program the shell would run
    2. dpkg -S <path>the package that owns that file
    Linux & shell cheat sheet →
  • rpm -qf "$(command -v <program>)"Linux & shellWhich package installed a command? (RHEL / Fedora / Amazon Linux)

    What each part does

    1. command -v <program>full path of the program
    2. rpm -qf <path>package (name-version-release) that owns that file
    Linux & shell cheat sheet →
  • dpkg-query -W -f='${Package} ${Version} ${Status}\n' <package>Linux & shellInstalled version of one package (Debian / Ubuntu)

    What each part does

    1. dpkg-query -Wshow installed package info
    2. -f='${Package} ${Version} ${Status}\n'output format: name, version, install status
    3. <package>package name; wildcards work, e.g. 'openssl*'
    Linux & shell cheat sheet →
  • apt-cache policy <package>Linux & shellInstalled vs available version (Debian / Ubuntu)

    What each part does

    1. apt-cache policyInstalled: version now, Candidate: what apt install/upgrade would get, plus the version table per repo
    2. <package>package name
    Linux & shell cheat sheet →
  • apt list -a <package>Linux & shellAll versions the repos offer (Debian / Ubuntu)

    What each part does

    1. apt list -aevery available version, marked [installed] / [upgradable]
    Linux & shell cheat sheet →
  • sudo apt update && apt list --upgradableLinux & shellPackages with updates available (Debian / Ubuntu)

    What each part does

    1. apt updaterefresh package lists first, or the answer is stale
    2. apt list --upgradableinstalled packages with a newer version: name, new version, [upgradable from: old]
    Linux & shell cheat sheet →
  • dpkg-query -W -f='${Package}\t${Version}\n' | sortLinux & shellEvery installed package with its version (Debian / Ubuntu)

    What each part does

    1. dpkg-query -W -f='...'name TAB version for every installed package
    2. | sortalphabetical; redirect to a file to diff two servers
    Linux & shell cheat sheet →
  • rpm -q <package>Linux & shellInstalled version of one package (RHEL / Fedora / Amazon Linux / SUSE)

    What each part does

    1. rpm -q <package>name-version-release.arch, or 'package ... is not installed'
    Linux & shell cheat sheet →
  • rpm -qi <package>Linux & shellDetails of an installed package (RHEL family)

    What each part does

    1. rpm -qiversion, release, install date, vendor, build date, summary
    Linux & shell cheat sheet →
  • dnf list --showduplicates <package>Linux & shellInstalled and available versions (RHEL / Fedora)

    What each part does

    1. dnf listInstalled Packages section and Available Packages section
    2. --showduplicatesevery available version, not just the newest (to pick one to install or downgrade)
    Linux & shell cheat sheet →
  • dnf check-updateLinux & shellPackages with updates available (RHEL / Fedora)

    What each part does

    1. dnf check-updatelist pending updates; exit code 100 means updates exist, 0 means none (yum check-update on older systems)
    Linux & shell cheat sheet →
  • dnf updateinfo list --securityLinux & shellPending security updates only (RHEL / Fedora)

    What each part does

    1. dnf updateinfo listadvisories for available updates
    2. --securityonly security fixes, with severity and advisory ID
    Linux & shell cheat sheet →
  • rpm -qa --last | head -30Linux & shellEvery installed package, newest installs first (RHEL family)

    What each part does

    1. rpm -qaall installed packages
    2. --lastsorted by install/update time, newest first, with the date
    3. | head -30the 30 most recent
    Linux & shell cheat sheet →
  • dnf history; dnf history info <id>Linux & shellWhat changed recently? (RHEL / Fedora)

    What each part does

    1. dnf historyevery install/upgrade/remove transaction with date and user
    2. dnf history info <id>exact packages and versions in that transaction; dnf history undo <id> reverts it
    Linux & shell cheat sheet →
  • grep -E ' (install|upgrade) ' /var/log/dpkg.logLinux & shellWhat was installed or upgraded recently? (Debian / Ubuntu)

    What each part does

    1. grep -E ' (install|upgrade) 'only install and upgrade lines (date, package, old and new version)
    2. /var/log/dpkg.logdpkg's log; older months are in dpkg.log.1 and .gz files (zgrep)
    Linux & shell cheat sheet →
  • apk info -v <package>; apk policy <package>Linux & shellInstalled version of one package (Alpine)

    What each part does

    1. apk info -v <package>installed name-version
    2. apk policy <package>installed and available versions per repository
    Linux & shell cheat sheet →
  • apk update && apk version -l '<'Linux & shellPackages with updates available (Alpine)

    What each part does

    1. apk updaterefresh the index
    2. apk version -l '<'only packages whose installed version is older than the repo's
    Linux & shell cheat sheet →
  • zypper info <package>Linux & shellInstalled version of one package (SUSE)

    What each part does

    1. zypper infoversion, repository, installed status of a package
    Linux & shell cheat sheet →
  • snap list; flatpak list --columns=application,versionLinux & shellSnap and Flatpak packages with versions

    What each part does

    1. snap listsnaps: name, version, revision, channel
    2. flatpak list --columns=...flatpak apps and their versions
    Linux & shell cheat sheet →
  • python3 -m pip list; python3 -m pip show <package>Linux & shellPython packages and versions

    What each part does

    1. python3 -m pip listevery package in this Python environment with its version (add --outdated for updates)
    2. pip show <package>version, location and dependencies of one package
    Linux & shell cheat sheet →
  • node --version; npm ls -g --depth=0Linux & shellGlobal Node.js packages and versions

    What each part does

    1. node --versionNode.js version
    2. npm ls -g --depth=0globally installed npm packages, top level only
    Linux & shell cheat sheet →
  • ldd --version | head -1; openssl version -a | head -2Linux & shellCore library versions (glibc, OpenSSL)

    What each part does

    1. ldd --versionthe C library (glibc) version; matters for binary compatibility and CVEs
    2. openssl version -aOpenSSL version and build date
    Linux & shell cheat sheet →
  • sudo apt install <package>=<version>Linux & shellInstall a specific version (Debian / Ubuntu)Caution

    What each part does

    1. <package>=<version>exact version from apt list -a; add --allow-downgrades to go back
    Linux & shell cheat sheet →
  • sudo dnf install <package>-<version>Linux & shellInstall a specific version (RHEL / Fedora)Caution

    What each part does

    1. <package>-<version>exact version from dnf list --showduplicates; dnf downgrade to go back
    Linux & shell cheat sheet →
  • sudo apt-mark hold <package>; sudo dnf versionlock add <package>Linux & shellStop a package from being upgraded

    What each part does

    1. apt-mark holdDebian / Ubuntu: keep the current version (apt-mark unhold to release)
    2. dnf versionlock addRHEL / Fedora: same idea (needs the versionlock plugin)
    Linux & shell cheat sheet →
  • dnf provides '*/<file>'; apt-file search <file>Linux & shellWhich package provides a file you don't have?

    What each part does

    1. dnf provides '*/<file>'RHEL family: packages containing that file
    2. apt-file search <file>Debian / Ubuntu (install apt-file and run apt-file update first)
    Linux & shell cheat sheet →
  • ansible all -i <inventory> -m shell -a "rpm -q <package> 2>/dev/null || dpkg-query -W <package>"Linux & shellCheck a package version across many servers

    What each part does

    1. ansible all -i <inventory>every host in the inventory
    2. -m shell -a "..."run the command on each one
    3. rpm -q <package> || dpkg-query -W <package>works on both RHEL- and Debian-family hosts

    Tip Without Ansible: for h in <host1> <host2>; do echo "$h: $(ssh $h 'rpm -q <package> 2>/dev/null || dpkg-query -W <package>')"; done

    Linux & shell cheat sheet →

System info, processes & disk63

  • uname -aLinux & shellKernel and architecture

    What each part does

    1. unamesystem information
    2. -aall: kernel name, hostname, release, version, architecture
    Linux & shell cheat sheet →
  • cat /etc/os-releaseLinux & shellWhich Linux distribution and version?

    What each part does

    1. /etc/os-releaseNAME, VERSION_ID, ID of the distro (ubuntu, debian, rhel…)
    Linux & shell cheat sheet →
  • hostname; hostname -ILinux & shellHost name and IP addresses

    What each part does

    1. hostnamethe machine name
    2. -Iall IP addresses of the host
    Linux & shell cheat sheet →
  • uptimeLinux & shellHow long has it been running? Load?

    What each part does

    1. uptimetime since boot, logged-in users, load average over 1/5/15 minutes
    Linux & shell cheat sheet →
  • date; timedatectlLinux & shellDate, time and timezone

    What each part does

    1. datecurrent date and time
    2. timedatectltimezone and whether NTP sync is active
    Linux & shell cheat sheet →
  • nproc; lscpuLinux & shellCPU cores and model

    What each part does

    1. nprocnumber of CPUs available
    2. lscpuCPU model, cores, threads, architecture
    Linux & shell cheat sheet →
  • lsblkLinux & shellDisks and partitions

    What each part does

    1. lsblkblock devices as a tree: disks, partitions, sizes, mount points
    Linux & shell cheat sheet →
  • findmntLinux & shellWhat is mounted where

    What each part does

    1. findmntmounted filesystems as a tree (cleaner than mount)
    Linux & shell cheat sheet →
  • sudo reboot; sudo shutdown -h nowLinux & shellReboot / shut downDestructive

    What each part does

    1. rebootrestart the machine
    2. shutdown -h now-h = halt/power off, now = immediately (or +10 for 10 minutes)
    Linux & shell cheat sheet →
  • ps aux | grep <name>Linux & shellFind a process by name

    What each part does

    1. pssnapshot of current processes
    2. auxBSD-style options (no dash): a = all users, u = user-oriented columns (USER, %CPU, %MEM…), x = include processes without a terminal
    3. |pipe the process list into grep
    4. grep <name>keep only lines containing <name>

    Tip The grep line itself matches too. Use grep "[n]ginx" (brackets on one letter) or pgrep -a <name>.

    Linux & shell cheat sheet →
  • ps aux --sort=-%mem | headLinux & shellTop 10 processes by memory

    What each part does

    1. ps auxall processes, user-oriented columns
    2. --sort=-%memsort by memory share; the leading "-" means descending
    3. | headkeep the first 10 lines (header + top 9)
    Linux & shell cheat sheet →
  • ps -eo pid,user,%cpu,%mem,comm --sort=-%cpu | head -n 15Linux & shellCustom columns sorted by CPU

    What each part does

    1. -eselect every process
    2. -o pid,user,%cpu,%mem,commchoose the output columns: PID, owner, CPU %, memory %, executable name
    3. --sort=-%cpuhighest CPU first
    4. head -n 15first 15 lines
    Linux & shell cheat sheet →
  • top -b -n 1 | head -n 20Linux & shellOne-shot top output (for logs or scripts)

    What each part does

    1. toplive process viewer
    2. -bbatch mode: plain text, no interactive screen (works in pipes)
    3. -n 1stop after one refresh
    4. head -n 20summary lines plus the top processes
    Linux & shell cheat sheet →
  • kill <pid>; sleep 5; kill -9 <pid>Linux & shellStop a process gracefully, then forcefullyCaution

    What each part does

    1. kill <pid>send SIGTERM (15): asks the process to exit and clean up
    2. sleep 5give it time to shut down
    3. kill -9 <pid>send SIGKILL: cannot be caught, ends it immediately (no cleanup)
    Linux & shell cheat sheet →
  • free -hLinux & shellMemory usage in human units

    What each part does

    1. freeshow RAM and swap usage
    2. -hhuman-readable units (Mi, Gi). Look at the "available" column, not "free"
    Linux & shell cheat sheet →
  • df -hT; df -iLinux & shellDisk space per filesystem (and inodes)

    What each part does

    1. dfreport filesystem usage
    2. -hhuman-readable sizes
    3. -Tshow the filesystem type
    4. df -iinode usage instead of space. A disk can be "full" on inodes
    Linux & shell cheat sheet →
  • du -sh * | sort -rh | headLinux & shellBiggest items in the current folder

    What each part does

    1. duestimate file/directory space
    2. -sone total per argument
    3. -hhuman-readable sizes
    4. *every entry in the current directory (shell glob)
    5. sort -rhsort human sizes (-h knows 2K < 1G), largest first (-r)
    6. headtop 10
    Linux & shell cheat sheet →
  • du -xh -d 1 <dir> | sort -rh | head -n 15Linux & shellFolder sizes one level deep, same filesystem

    What each part does

    1. -xdon't cross into other mounted filesystems
    2. -hhuman-readable
    3. -d 1only show totals one level below <dir> (same as --max-depth=1)
    4. sort -rh | head -n 15largest 15
    Linux & shell cheat sheet →
  • crontab -l; crontab -eLinux & shellList and edit your cron jobs

    What each part does

    1. crontab -lshow your user's cron jobs (sudo crontab -l -u <user> for others)
    2. crontab -eedit them in $EDITOR
    Linux & shell cheat sheet →
  • */5 * * * * /usr/local/bin/<script> >> /var/log/<script>.log 2>&1Linux & shellCron line format

    What each part does

    1. */5 * * * *minute hour day-of-month month day-of-week: here every 5 minutes
    2. /usr/local/bin/<script>use full paths: cron has a minimal PATH
    3. >> <log> 2>&1append output and errors to a log, otherwise they are mailed or lost
    Linux & shell cheat sheet →
  • ls /etc/cron.d /etc/cron.daily /etc/cron.hourly; cat /etc/crontabLinux & shellSystem-wide cron jobs

    What each part does

    1. /etc/cron.djob files from packages and admins (with a user field)
    2. /etc/cron.daily, hourly...scripts run by run-parts at those intervals
    Linux & shell cheat sheet →
  • journalctl -u cron -u crond --since todayLinux & shellDid cron run my job?

    What each part does

    1. journalctl -u cron -u crondcron daemon logs (cron on Debian, crond on RHEL); or grep CRON /var/log/syslog
    2. --since todayonly today
    Linux & shell cheat sheet →
  • systemctl list-timers --allLinux & shellList systemd timers and when they run next

    What each part does

    1. list-timersevery timer: next run, last run, the unit it starts
    2. --allinclude inactive timers
    Linux & shell cheat sheet →
  • echo '<command>' | at 02:00Linux & shellRun a command once at a later time

    What each part does

    1. at 02:00run once at 2 AM (also: at now + 30 minutes); atq lists, atrm removes
    Linux & shell cheat sheet →
  • lsblk -fLinux & shellDisks, partitions and filesystems

    What each part does

    1. lsblkblock devices as a tree: disks, partitions, LVM volumes
    2. -fadd filesystem type, label, UUID and mount point
    Linux & shell cheat sheet →
  • sudo mount <device> <mount-point>Linux & shellMount a filesystem

    What each part does

    1. mount <device>e.g. /dev/sdb1 or /dev/mapper/vg-data
    2. <mount-point>existing empty directory, e.g. /mnt/data
    Linux & shell cheat sheet →
  • sudo findmnt --verify && sudo mount -aLinux & shellTest /etc/fstab before rebooting

    What each part does

    1. findmnt --verifycheck fstab syntax, devices and filesystem types
    2. mount -amount everything in fstab now; a typo here would otherwise stop the next boot
    Linux & shell cheat sheet →
  • sudo umount <mount-point> || sudo lsof +f -- <mount-point>Linux & shellUnmount, and find what keeps it busy

    What each part does

    1. umountunmount
    2. lsof +f -- <mount-point>processes with files open there (target is busy)
    Linux & shell cheat sheet →
  • sudo mkfs.ext4 -L <label> <device>Linux & shellCreate a filesystem on a new diskDestructive

    What each part does

    1. mkfs.ext4format as ext4 (mkfs.xfs for XFS): erases the device
    2. -L <label>filesystem label
    Linux & shell cheat sheet →
  • sudo growpart <disk> <partition-number> && sudo resize2fs <partition>Linux & shellGrow a partition and filesystem after enlarging a cloud diskCaution

    What each part does

    1. growpart /dev/xvda 1extend partition 1 to fill the disk (cloud-guest-utils)
    2. resize2fs <partition>grow an ext4 filesystem; for XFS: xfs_growfs <mount-point>
    Linux & shell cheat sheet →
  • sudo pvs; sudo vgs; sudo lvsLinux & shellLVM overview

    What each part does

    1. pvsphysical volumes (disks in LVM)
    2. vgsvolume groups and their free space
    3. lvslogical volumes and sizes
    Linux & shell cheat sheet →
  • sudo lvextend -r -L +<size>G /dev/<vg>/<lv>Linux & shellExtend a logical volume and its filesystemCaution

    What each part does

    1. lvextendgrow a logical volume
    2. -ralso resize the filesystem in one step
    3. -L +<size>Gadd this much (or -l +100%FREE for all free space)
    Linux & shell cheat sheet →
  • swapon --show; sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfileLinux & shellShow swap, and add a swap file

    What each part does

    1. swapon --showactive swap devices and usage
    2. fallocate -l 2G /swapfilecreate a 2 GB file
    3. chmod 600only root may read it
    4. mkswap / swaponformat it as swap and enable it (add to fstab to keep it)
    Linux & shell cheat sheet →
  • df -iLinux & shellOut of inodes? (disk full with free space left)

    What each part does

    1. df -iinode usage per filesystem; 100% means no new files even if space is free (millions of tiny files)
    Linux & shell cheat sheet →
  • sudo dmesg -T | tail -50Linux & shellKernel messages with readable times

    What each part does

    1. dmesgkernel ring buffer: hardware errors, OOM killer, disk and network driver messages
    2. -Thuman-readable timestamps
    3. | tail -50the latest 50 lines
    Linux & shell cheat sheet →
  • sudo dmesg -T | grep -i -E 'killed process|out of memory'Linux & shellDid the OOM killer kill something?

    What each part does

    1. grep -i -E '...'lines where the kernel killed a process to free memory, with its name and memory use
    Linux & shell cheat sheet →
  • lscpu; lspci; sudo dmidecode -t systemLinux & shellHardware overview

    What each part does

    1. lscpuCPU model, cores, threads, virtualization
    2. lspciPCI devices: NICs, GPUs, storage controllers
    3. dmidecode -t systemvendor, model and serial number
    Linux & shell cheat sheet →
  • sysctl <key>; sudo sysctl -w <key>=<value>Linux & shellRead and change kernel parametersCaution

    What each part does

    1. sysctl <key>e.g. vm.swappiness, net.ipv4.ip_forward, fs.file-max
    2. sysctl -w <key>=<value>change it now; put it in /etc/sysctl.d/*.conf to keep it after reboot
    Linux & shell cheat sheet →
  • ulimit -n; cat /proc/<pid>/limitsLinux & shellOpen-file and process limits

    What each part does

    1. ulimit -nmax open files for this shell (Too many open files means you hit it)
    2. /proc/<pid>/limitsthe actual limits of a running process (systemd services set LimitNOFILE)
    Linux & shell cheat sheet →
  • lsmod | grep <module>; sudo modprobe <module>Linux & shellKernel modules

    What each part does

    1. lsmodloaded modules
    2. modprobe <module>load a module with its dependencies (e.g. br_netfilter for Kubernetes)
    Linux & shell cheat sheet →
  • timedatectlLinux & shellTime, timezone and NTP sync

    What each part does

    1. timedatectllocal time, UTC, timezone and whether the clock is NTP-synchronized (clock skew breaks TLS and tokens)
    Linux & shell cheat sheet →
  • uptimeLinux & shellUptime and load average

    What each part does

    1. uptimehow long since boot, users, and 1/5/15-minute load averages (compare with CPU count)
    Linux & shell cheat sheet →
  • vmstat 1 5Linux & shellCPU, memory, swap and I/O wait every second

    What each part does

    1. vmstatr (run queue), free memory, si/so (swapping), wa (I/O wait), us/sy/id CPU
    2. 1 5every 1 second, 5 times (the first line is the average since boot)
    Linux & shell cheat sheet →
  • iostat -xz 1Linux & shellDisk I/O per device

    What each part does

    1. iostatdisk statistics (sysstat package)
    2. -xextended: %util, await (latency), r/s, w/s
    3. -zhide idle devices
    4. 1refresh every second
    Linux & shell cheat sheet →
  • mpstat -P ALL 1Linux & shellCPU usage per core

    What each part does

    1. mpstatCPU statistics (sysstat)
    2. -P ALLevery core, to spot one core at 100%
    3. 1every second
    Linux & shell cheat sheet →
  • pidstat -u -r -d 1Linux & shellCPU, memory and I/O per process over time

    What each part does

    1. pidstatper-process statistics (sysstat)
    2. -u -r -dCPU, memory (faults, RSS) and disk I/O
    3. 1every second
    Linux & shell cheat sheet →
  • sudo iotop -oPaLinux & shellWhich processes do the most disk I/O?

    What each part does

    1. iotoptop for disk I/O
    2. -oonly processes actually doing I/O
    3. -Pper process, not per thread
    4. -aaccumulated totals
    Linux & shell cheat sheet →
  • ps -eo pid,user,%mem,rss,cmd --sort=-rss | head -15Linux & shellTop memory users

    What each part does

    1. ps -eo ...pick columns: PID, user, % of RAM, resident memory in KB, command
    2. --sort=-rssbiggest memory first
    3. | head -15top 14 plus the header
    Linux & shell cheat sheet →
  • sudo strace -f -tt -p <pid> -e trace=network,fileLinux & shellTrace what a process is doing (system calls)

    What each part does

    1. strace -p <pid>attach to a running process
    2. -ffollow its threads and children
    3. -tttimestamps with microseconds
    4. -e trace=network,fileonly network and file calls (drop it to see everything)

    Tip Slows the process down a lot; use briefly in production.

    Linux & shell cheat sheet →
  • sudo perf topLinux & shellLive CPU profile of the whole system

    What each part does

    1. perf topfunctions using the most CPU right now, across kernel and user space
    Linux & shell cheat sheet →
  • sar -n DEV 1Linux & shellNetwork traffic per interface

    What each part does

    1. sar -n DEVpackets and KB per second per interface (sysstat)
    2. 1every second; sar without a count reads history if sysstat collection is enabled
    Linux & shell cheat sheet →
  • watch -n 2 -d '<command>'Linux & shellRe-run a command every few seconds

    What each part does

    1. watchrun the command repeatedly, full-screen
    2. -n 2every 2 seconds
    3. -dhighlight what changed
    Linux & shell cheat sheet →
  • kubectl cordon <node>KubernetesStop new pods landing on a node

    What each part does

    1. cordonmark unschedulable; running pods stay (drain to evict them, uncordon to undo)
    Kubernetes cheat sheet →
  • kubectl taint nodes <node> <key>=<value>:NoSchedule; kubectl taint nodes <node> <key>:NoSchedule-KubernetesTaint a node / remove a taint

    What each part does

    1. <key>=<value>:NoScheduleonly pods tolerating this taint can schedule here (NoExecute also evicts)
    2. <key>:NoSchedule-trailing minus removes it
    Kubernetes cheat sheet →
  • kubectl label node <node> <key>=<value>KubernetesLabel a node

    What each part does

    1. label nodeused by nodeSelector / affinity, e.g. disktype=ssd
    Kubernetes cheat sheet →
  • kubectl get nodes --show-labels; kubectl describe node <node> | grep -A3 TaintsKubernetesNode labels and taints

    What each part does

    1. --show-labelsall labels (zone, instance type, OS, arch)
    2. grep -A3 Taintstaints on the node
    Kubernetes cheat sheet →
  • kubectl describe node <node> | grep -A8 'Allocated resources'KubernetesHow full is a node? (requests vs capacity)

    What each part does

    1. Allocated resourcessum of CPU/memory requests and limits vs allocatable: why pods are Pending even if usage is low
    Kubernetes cheat sheet →
  • kubectl auth can-i <verb> <resource> -n <namespace> --as=<user-or-sa>KubernetesCan I (or someone) do this?

    What each part does

    1. auth can-iyes/no for an action, e.g. can-i delete pods
    2. --as=<user-or-sa>impersonate, e.g. system:serviceaccount:<ns>:<sa>
    Kubernetes cheat sheet →
  • kubectl auth can-i --list -n <namespace>KubernetesEverything I am allowed to do

    What each part does

    1. --listall verbs per resource for the current user in that namespace
    Kubernetes cheat sheet →
  • kubectl auth whoamiKubernetesWho am I logged in as?

    What each part does

    1. auth whoamiuser name and groups the API server sees for your credentials
    Kubernetes cheat sheet →
  • kubectl create token <serviceaccount> -n <namespace> --duration=1hKubernetesCreate a short-lived token for a service account

    What each part does

    1. create tokenrequest a bound token (no long-lived secret)
    2. --duration=1hlifetime
    Kubernetes cheat sheet →
  • kubectl get csr; kubectl certificate approve <csr>KubernetesApprove a certificate signing requestCaution

    What each part does

    1. get csrpending node / user certificate requests
    2. certificate approvesign it
    Kubernetes cheat sheet →
  • kubectl versionKubernetesClient and server versions

    What each part does

    1. kubectl versionclient and API server versions; keep kubectl within one minor version of the server
    Kubernetes cheat sheet →

Network & SSH40

  • ping -c 4 <host>Linux & shellIs a host reachable?

    What each part does

    1. pingsend ICMP echo requests
    2. -c 4stop after 4 packets (otherwise it runs until Ctrl+C)
    Linux & shell cheat sheet →
  • ssh <user>@<host>Linux & shellLog in to a server

    What each part does

    1. sshsecure shell
    2. <user>@<host>remote user name and host name or IP
    Linux & shell cheat sheet →
  • ssh -p <port> -i <key-file> <user>@<host>Linux & shellSSH with a port and a key file

    What each part does

    1. -p <port>remote port (default 22)
    2. -i <key-file>private key to use
    Linux & shell cheat sheet →
  • ssh <user>@<host> "<command>"Linux & shellRun one command remotely

    What each part does

    1. "<command>"runs on the server, output comes back to you
    Linux & shell cheat sheet →
  • ssh-keygen -t ed25519 -C "<email>"Linux & shellCreate an SSH key

    What each part does

    1. ssh-keygengenerate a key pair
    2. -t ed25519key type (ed25519 is the modern default)
    3. -C "<email>"comment stored in the key, to recognise it

    Tip Creates ~/.ssh/id_ed25519 (private, keep secret) and id_ed25519.pub (public).

    Linux & shell cheat sheet →
  • ssh-copy-id <user>@<host>Linux & shellInstall your public key on a server

    What each part does

    1. ssh-copy-idappend your public key to ~/.ssh/authorized_keys on the server
    Linux & shell cheat sheet →
  • wget <url>Linux & shellDownload a file

    What each part does

    1. wgetdownload to the current folder (curl -O <url> does the same)
    Linux & shell cheat sheet →
  • nc -zv <host> <port>Linux & shellIs a TCP port open?

    What each part does

    1. ncnetcat
    2. -zjust scan, send no data
    3. -vverbose: say "succeeded" or "refused"
    Linux & shell cheat sheet →
  • traceroute <host>Linux & shellPath packets take to a host

    What each part does

    1. traceroutelist every hop (router) on the way; shows where it stops
    Linux & shell cheat sheet →
  • ip aLinux & shellShow IP addresses

    What each part does

    1. ip ashort for ip address: every interface with its IPs
    Linux & shell cheat sheet →
  • ss -tulpnLinux & shellWhich process listens on which port

    What each part does

    1. sssocket statistics (modern netstat)
    2. -tTCP sockets
    3. -uUDP sockets
    4. -llistening sockets only
    5. -pshow the owning process (needs sudo for other users’ processes)
    6. -nnumeric ports and addresses, no name lookups
    Linux & shell cheat sheet →
  • sudo lsof -i :<port>Linux & shellWho is using a port

    What each part does

    1. lsoflist open files (sockets are files too)
    2. -ionly network sockets
    3. :<port>filter to that port
    Linux & shell cheat sheet →
  • ip -br addr; ip routeLinux & shellInterfaces and routes

    What each part does

    1. ip -br addrevery interface with its addresses, one line each (-br = brief)
    2. ip routerouting table, including the default gateway
    Linux & shell cheat sheet →
  • curl -sS -o /dev/null -w "%{http_code} %{time_total}s\n" <url>Linux & shellCheck an HTTP endpoint: status code and time

    What each part does

    1. -ssilent: no progress bar
    2. -Sbut still show errors
    3. -o /dev/nullthrow away the response body
    4. -w "…"print a custom line after the request: %{http_code} = status, %{time_total} = seconds
    Linux & shell cheat sheet →
  • curl -fsSL <url> -o <file>Linux & shellDownload a file, following redirects, failing on HTTP errors

    What each part does

    1. -ffail (non-zero exit, no output) on HTTP 4xx/5xx
    2. -s -Squiet, but show errors
    3. -Lfollow redirects
    4. -o <file>write the body to <file>
    Linux & shell cheat sheet →
  • sudo ufw status verboseLinux & shellFirewall status and rules (Ubuntu ufw)

    What each part does

    1. ufw statusactive or not, and each allow/deny rule
    2. verbosealso default policies and logging level
    Linux & shell cheat sheet →
  • sudo ufw allow <port>/tcpLinux & shellAllow a port (ufw)Caution

    What each part does

    1. ufw allowadd an allow rule (ufw allow from <ip> to any port <port> to restrict the source)
    2. <port>/tcpport and protocol
    Linux & shell cheat sheet →
  • sudo firewall-cmd --list-allLinux & shellFirewall rules (RHEL firewalld)

    What each part does

    1. firewall-cmd --list-allthe default zone's services, ports, rich rules and interfaces
    Linux & shell cheat sheet →
  • sudo firewall-cmd --permanent --add-port=<port>/tcp && sudo firewall-cmd --reloadLinux & shellOpen a port permanently (firewalld)Caution

    What each part does

    1. --permanentsave to config (without it the rule is lost on reload)
    2. --add-port=<port>/tcpopen the port in the default zone (or --add-service=https)
    3. --reloadapply the saved config
    Linux & shell cheat sheet →
  • sudo iptables -L -n -v --line-numbersLinux & shellList iptables rules with counters

    What each part does

    1. -Llist rules of the filter table
    2. -nnumeric, no DNS lookups
    3. -vpacket/byte counters and interfaces
    4. --line-numbersrule numbers, for deleting by number
    Linux & shell cheat sheet →
  • sudo iptables -t nat -L -n -vLinux & shellList NAT rules (port forwards, Docker, Kubernetes)

    What each part does

    1. -t natthe NAT table: DNAT port forwards and MASQUERADE rules
    Linux & shell cheat sheet →
  • sudo nft list rulesetLinux & shellShow the full nftables ruleset

    What each part does

    1. nft list rulesetevery table, chain and rule (newer distros use nftables under firewalld and iptables-nft)
    Linux & shell cheat sheet →
  • openssl s_client -connect <host>:443 -servername <host> -showcerts </dev/nullLinux & shellShow a server's certificate and chain

    What each part does

    1. s_client -connect <host>:443open a TLS connection
    2. -servername <host>send SNI, so you get the right certificate on shared IPs
    3. -showcertsprint every certificate the server sends
    4. </dev/nullclose the connection right after the handshake
    Linux & shell cheat sheet →
  • openssl s_client -connect <host>:443 -servername <host> </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -datesLinux & shellWhen does a site's certificate expire?

    What each part does

    1. openssl s_client ...fetch the certificate
    2. | openssl x509 -nooutparse it without printing the encoded certificate
    3. -subject -issuer -dateswho it is for, who signed it, notBefore and notAfter
    Linux & shell cheat sheet →
  • openssl x509 -in <cert>.pem -noout -textLinux & shellRead a certificate file

    What each part does

    1. x509 -in <cert>.pema PEM certificate file
    2. -noout -textfull details: subject, SANs (DNS names), validity, key size
    Linux & shell cheat sheet →
  • openssl x509 -noout -pubkey -in <cert>.pem | sha256sum; openssl pkey -pubout -in <key>.pem | sha256sumLinux & shellDoes this key belong to this certificate?

    What each part does

    1. x509 -pubkeypublic key from the certificate
    2. pkey -puboutpublic key derived from the private key
    3. sha256sumthe two hashes must be identical
    Linux & shell cheat sheet →
  • openssl req -new -newkey rsa:2048 -nodes -keyout <name>.key -out <name>.csr -subj "/CN=<domain>"Linux & shellCreate a private key and a CSR

    What each part does

    1. req -newnew certificate signing request
    2. -newkey rsa:2048 -nodesgenerate a 2048-bit key, not encrypted with a passphrase
    3. -keyout / -outwhere to write the key and the CSR
    4. -subj "/CN=<domain>"subject; add -addext "subjectAltName=DNS:<domain>" for SANs
    Linux & shell cheat sheet →
  • openssl req -x509 -newkey rsa:2048 -nodes -days 365 -keyout <name>.key -out <name>.crt -subj "/CN=<domain>"Linux & shellSelf-signed certificate for testing

    What each part does

    1. req -x509output a self-signed certificate instead of a CSR
    2. -days 365valid for a year
    Linux & shell cheat sheet →
  • openssl verify -CAfile <ca-bundle>.pem <cert>.pemLinux & shellCheck a certificate against a CA bundle

    What each part does

    1. openssl verifyOK if the chain validates; otherwise the reason (expired, unable to get issuer)
    2. -CAfiletrusted CA and intermediates
    Linux & shell cheat sheet →
  • openssl s_client -connect <host>:443 -tls1_2 </dev/null; openssl s_client -connect <host>:443 -tls1_3 </dev/nullLinux & shellWhich TLS versions does a server accept?

    What each part does

    1. -tls1_2 / -tls1_3force one protocol version; a handshake failure means it's not supported
    Linux & shell cheat sheet →
  • sudo tcpdump -i any -nn port <port>Linux & shellCapture traffic on a port

    What each part does

    1. tcpdumppacket capture
    2. -i anyall interfaces
    3. -nndon't resolve names or ports
    4. port <port>filter: only traffic on that port (also host <ip>, tcp, udp)
    Linux & shell cheat sheet →
  • sudo tcpdump -i <interface> -w <file>.pcap -c 10000 host <ip>Linux & shellSave a capture for Wireshark

    What each part does

    1. -w <file>.pcapwrite raw packets to a file
    2. -c 10000stop after 10,000 packets
    3. host <ip>only traffic to or from this IP
    Linux & shell cheat sheet →
  • ip route get <ip>Linux & shellWhich route and source IP would be used?

    What each part does

    1. ip route getthe exact route, gateway, interface and source address the kernel would use
    Linux & shell cheat sheet →
  • mtr -rwc 50 <host>Linux & shellPath and packet loss to a host

    What each part does

    1. mtrtraceroute and ping combined, per hop
    2. -r -wreport mode with wide (untruncated) host names
    3. -c 5050 probes per hop
    Linux & shell cheat sheet →
  • nmap -Pn -p 1-1024 <host>Linux & shellScan a host's open ports

    What each part does

    1. nmapport scanner (only scan hosts you're allowed to)
    2. -Pnskip the ping check (many hosts block ping)
    3. -p 1-1024port range (or -p 22,80,443)
    Linux & shell cheat sheet →
  • ss -sLinux & shellSocket summary

    What each part does

    1. ss -stotals of TCP states: established, time-wait, orphaned; spot connection leaks
    Linux & shell cheat sheet →
  • ss -tn state established | awk 'NR>1 {split($4,a,":"); print a[1]}' | sort | uniq -c | sort -rn | headLinux & shellConnections per remote IP

    What each part does

    1. ss -tn state establishedopen TCP connections, numeric
    2. awk '...'take the peer address column and strip the port
    3. sort | uniq -c | sort -rn | headcount per IP, busiest first
    Linux & shell cheat sheet →
  • ip neighLinux & shellARP / neighbour table

    What each part does

    1. ip neighIP to MAC mappings; FAILED or INCOMPLETE entries point to layer 2 problems
    Linux & shell cheat sheet →
  • curl -sv --resolve <host>:443:<ip> https://<host>/Linux & shellTest a URL against a specific IP (skip DNS)

    What each part does

    1. --resolve <host>:443:<ip>use this IP for that host and port, keeping the right SNI and Host header
    2. -svquiet progress, verbose headers and TLS
    Linux & shell cheat sheet →
  • nc -l <port>Linux & shellListen on a port to test reachability

    What each part does

    1. nc -l <port>listen; from another machine nc -zv <host> <port> or curl shows whether traffic gets through
    Linux & shell cheat sheet →

Find & inspect66

  • docker ps -a | grep <container-id>DockerFind a container by ID or name in the full list

    What each part does

    1. docker pslist containers (running only by default)
    2. -a--all: include stopped / exited containers too
    3. |pipe the table into grep
    4. grep <container-id>keep only the row that contains that ID (a prefix like 3f2a is enough) or name

    Tip Built-in alternative without grep: docker ps -a --filter id=<container-id> (or --filter name=<name>).

    Docker cheat sheet →
  • docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"DockerOnly running containers, compact table

    What each part does

    1. docker psrunning containers
    2. --format "table …"Go template output; "table" adds column headers
    3. {{.Names}} {{.Status}} {{.Ports}}fields to show; \t separates columns
    Docker cheat sheet →
  • docker ps -a --filter status=exited --filter name=<name>DockerFilter containers by state, name or image

    What each part does

    1. -aall containers
    2. --filter status=exitedonly exited ones (also: running, paused, restarting…)
    3. --filter name=<name>name contains <name>. Repeating --filter combines them
    Docker cheat sheet →
  • docker ps -qDockerJust the IDs (for scripting)

    What each part does

    1. -q--quiet: print only container IDs, one per line
    Docker cheat sheet →
  • docker inspect --format '{{.State.ExitCode}} OOMKilled={{.State.OOMKilled}}' <container>DockerWhy did it stop? Exit code and OOM

    What each part does

    1. docker inspect <container>full JSON details of the container
    2. --format '…'Go template: print only the fields you ask for
    3. {{.State.ExitCode}}0 = clean exit, 137 = killed (often out of memory), 143 = SIGTERM
    4. {{.State.OOMKilled}}true if the kernel killed it for exceeding its memory limit
    Docker cheat sheet →
  • docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' <container>DockerContainer IP address

    What each part does

    1. range .NetworkSettings.Networksloop over every network the container is attached to
    2. {{.IPAddress}}print its IP on that network
    Docker cheat sheet →
  • docker stats --no-streamDockerLive CPU / memory per container

    What each part does

    1. docker statsresource usage of running containers
    2. --no-streamprint one snapshot and exit instead of refreshing
    Docker cheat sheet →
  • docker exec <container> envDockerPrint all environment variables of a running container

    What each part does

    1. docker exec <container>run a command inside the running container
    2. envprint every environment variable the container's processes see, KEY=value per line

    Tip Needs a running container that has env (most images do; distroless ones don't). For a stopped container use the inspect version below.

    Docker cheat sheet →
  • docker exec <container> printenv <VAR>DockerPrint one environment variable

    What each part does

    1. docker exec <container>run inside the container
    2. printenv <VAR>print only that variable's value; exit code 1 if it isn't set
    Docker cheat sheet →
  • docker inspect <container> --format '{{range .Config.Env}}{{println .}}{{end}}'DockerShow env vars from the container config (works when stopped)

    What each part does

    1. docker inspect <container>read the container's stored configuration; no exec needed
    2. --format '...'Go template to pick fields
    3. {{range .Config.Env}}loop over the Env list (from the image ENV, -e and --env-file)
    4. {{println .}}print each KEY=value on its own line

    Tip Shows the configured env, not variables a process exported at runtime. Secrets passed with -e are visible here: anyone with docker access can read them.

    Docker cheat sheet →
  • docker image inspect <image>:<tag> --format '{{json .Config.Env}}'DockerShow env vars baked into an image

    What each part does

    1. docker image inspect <image>:<tag>metadata of a local image
    2. {{json .Config.Env}}the ENV values from the Dockerfile (PATH, versions...) as a JSON list
    Docker cheat sheet →
  • docker run --rm <image>:<tag> envDockerPrint the env a fresh container would get

    What each part does

    1. docker run --rmstart a throwaway container, removed when it exits
    2. <image>:<tag>the image to test
    3. envoverride the command: just print the environment
    Docker cheat sheet →
  • docker compose exec <service> envDockerPrint the env of a Compose service

    What each part does

    1. docker compose exec <service>run inside the running service container
    2. envprint its environment, after .env and environment: substitution

    Tip To check the values before starting anything, use docker compose config.

    Docker cheat sheet →
  • docker inspect <container> --format 'Entrypoint={{json .Config.Entrypoint}} Cmd={{json .Config.Cmd}}'DockerShow the entrypoint and command a container runs

    What each part does

    1. docker inspect <container>container config
    2. {{json .Config.Entrypoint}}the ENTRYPOINT (the program that always runs)
    3. {{json .Config.Cmd}}the CMD (default arguments, replaced by what you type after the image name)
    Docker cheat sheet →
  • docker inspect <container> --format '{{json .Mounts}}' | jqDockerShow mounts (volumes and bind mounts)

    What each part does

    1. {{json .Mounts}}every mount: type, source on the host, destination in the container, read-only flag
    2. | jqpretty-print the JSON
    Docker cheat sheet →
  • docker inspect <container> --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}'DockerShow the container's IP address(es)

    What each part does

    1. {{range .NetworkSettings.Networks}}loop over every network the container is attached to
    2. {{.IPAddress}}its IP on that network
    Docker cheat sheet →
  • docker inspect <container> --format 'restart={{.HostConfig.RestartPolicy.Name}} memory={{.HostConfig.Memory}} cpus={{.HostConfig.NanoCpus}}'DockerShow restart policy and resource limits

    What each part does

    1. {{.HostConfig.RestartPolicy.Name}}no, always, on-failure or unless-stopped
    2. {{.HostConfig.Memory}}memory limit in bytes (0 = unlimited)
    3. {{.HostConfig.NanoCpus}}CPU limit in billionths of a CPU (1000000000 = 1 CPU, 0 = unlimited)
    Docker cheat sheet →
  • docker inspect <container> --format '{{json .State.Health}}' | jqDockerShow the health check status and last results

    What each part does

    1. {{json .State.Health}}status (starting / healthy / unhealthy), failing streak, and the output of the last checks
    2. | jqpretty-print
    Docker cheat sheet →
  • docker inspect <container> --format '{{json .Config.Labels}}' | jqDockerShow labels (Compose project, versions, maintainers)

    What each part does

    1. {{json .Config.Labels}}all labels as JSON, e.g. com.docker.compose.service and org.opencontainers.image.version
    2. | jqpretty-print
    Docker cheat sheet →
  • docker exec <container> cat /etc/os-releaseDockerWhich OS and version is the container based on?

    What each part does

    1. docker exec <container>run inside the container
    2. cat /etc/os-releasedistro name and version, e.g. Debian 12, Alpine 3.20, UBI 9
    Docker cheat sheet →
  • docker exec <container> sh -c 'dpkg -l 2>/dev/null || rpm -qa 2>/dev/null || apk info -v'DockerList installed OS packages with versions (any distro)

    What each part does

    1. sh -c '...'run a small shell script inside the container
    2. dpkg -lDebian / Ubuntu packages and versions
    3. 2>/dev/null ||hide the error and try the next tool if this one doesn't exist
    4. rpm -qaRHEL / UBI / Amazon Linux packages
    5. apk info -vAlpine packages with versions
    Docker cheat sheet →
  • docker exec <container> sh -c 'dpkg-query -W <package> 2>/dev/null || rpm -q <package> 2>/dev/null || apk info -v <package>'DockerVersion of one package in a container

    What each part does

    1. dpkg-query -W <package>Debian / Ubuntu: name and installed version
    2. rpm -q <package>RHEL family: name-version-release
    3. apk info -v <package>Alpine: name-version
    Docker cheat sheet →
  • docker run --rm <image>:<tag> <program> --versionDockerVersion of the app runtime in an image

    What each part does

    1. docker run --rm <image>:<tag>throwaway container from the image
    2. <program> --versione.g. node --version, python3 --version, java -version, nginx -v
    Docker cheat sheet →
  • docker image inspect <image>:<tag> --format '{{index .Config.Labels "org.opencontainers.image.version"}}'DockerImage version labels (OCI annotations)

    What each part does

    1. docker image inspect <image>:<tag>image metadata
    2. {{index .Config.Labels "..."}}read one label; the OCI version label is set by many official images and good pipelines
    Docker cheat sheet →
  • docker image inspect <image>:<tag> --format '{{.Id}} {{index .RepoDigests 0}} {{.Created}} {{.Os}}/{{.Architecture}}'DockerImage ID, digest, created date and architecture

    What each part does

    1. {{.Id}}local image ID
    2. {{index .RepoDigests 0}}registry digest (repo@sha256:...) to pin exactly this image
    3. {{.Created}}build date
    4. {{.Os}}/{{.Architecture}}platform, e.g. linux/amd64 or linux/arm64
    Docker cheat sheet →
  • docker inspect <container> --format '{{.Config.Image}} {{.Image}}'DockerWhich image (and digest) is a container running?

    What each part does

    1. {{.Config.Image}}the name:tag it was started from
    2. {{.Image}}the exact image ID, so you can tell if :latest has moved since
    Docker cheat sheet →
  • docker manifest inspect <image>:<tag> | jq '.manifests[].platform'DockerCheck which platforms an image supports, without pulling

    What each part does

    1. docker manifest inspectread the image manifest from the registry
    2. | jq '.manifests[].platform'list os/architecture of every variant (multi-arch images)
    Docker cheat sheet →
  • docker scout quickview <image>:<tag>DockerQuick vulnerability overview of an image

    What each part does

    1. docker scout quickviewsummary of known CVEs by severity and base image update advice (Docker Scout plugin)
    2. <image>:<tag>local or registry image

    Tip docker scout cves <image> lists every CVE. Trivy does the same without Docker's plugin.

    Docker cheat sheet →
  • kubectl get po -n <namespace>KubernetesList pods

    What each part does

    1. kubectl getlist resources
    2. poshort name for pods: NAME, READY, STATUS, RESTARTS, AGE
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get po -o wide -n <namespace>KubernetesList pods with node and IP

    What each part does

    1. popods
    2. -o wideadd the pod IP, the node it runs on and nominated node
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get svc -n <namespace>KubernetesList services

    What each part does

    1. svcshort name for services: TYPE, CLUSTER-IP, EXTERNAL-IP, PORT(S)
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get svc -o wide -n <namespace>KubernetesList services with their selectors

    What each part does

    1. svc -o wideadd the SELECTOR column: which pod labels the service sends traffic to
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get endpointslices -l kubernetes.io/service-name=<service> -n <namespace>KubernetesWhich pods is a service sending traffic to?

    What each part does

    1. endpointslicesthe actual pod IPs:ports behind services (kubectl get ep <service> on older clusters)
    2. -l kubernetes.io/service-name=<service>only the slices of this service
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)

    Tip Empty ENDPOINTS means the selector matches no ready pods: compare kubectl get svc -o wide with kubectl get po --show-labels.

    Kubernetes cheat sheet →
  • kubectl get deploy -n <namespace>KubernetesList deployments

    What each part does

    1. deploydeployments: READY (ready/desired), UP-TO-DATE, AVAILABLE
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get rs -n <namespace>KubernetesList ReplicaSets

    What each part does

    1. rsReplicaSets; old ones with 0 replicas are kept for rollbacks
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get sts,ds -n <namespace>KubernetesList StatefulSets and DaemonSets

    What each part does

    1. stsStatefulSets
    2. dsDaemonSets: desired / current / ready per node
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get ing -AKubernetesList ingresses

    What each part does

    1. ingingresses: class, hosts, address, ports
    2. -Aall namespaces
    Kubernetes cheat sheet →
  • kubectl get cm,secret -n <namespace>KubernetesList ConfigMaps and Secrets

    What each part does

    1. cmConfigMaps
    2. secretSecrets (values are not shown)
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get pv,pvc -AKubernetesList volumes and claims

    What each part does

    1. pvPersistentVolumes (cluster-wide): capacity, status, claim
    2. pvcPersistentVolumeClaims: Bound / Pending
    3. -Aall namespaces for the claims
    Kubernetes cheat sheet →
  • kubectl get scKubernetesList storage classes

    What each part does

    1. scStorageClasses; (default) marks the one used when a PVC names none
    Kubernetes cheat sheet →
  • kubectl get jobs,cj -n <namespace>KubernetesList jobs and cronjobs

    What each part does

    1. jobsJobs: completions, duration
    2. cjCronJobs: schedule, last schedule, active
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get hpa -n <namespace>KubernetesList autoscalers

    What each part does

    1. hpaHorizontalPodAutoscalers: target metric vs current, min/max/current replicas
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get sa -n <namespace>KubernetesList service accounts

    What each part does

    1. saServiceAccounts
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get netpol -n <namespace>KubernetesList network policies

    What each part does

    1. netpolNetworkPolicies and the pods they select
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get crdKubernetesList custom resource types

    What each part does

    1. crdCustomResourceDefinitions installed by operators and add-ons
    Kubernetes cheat sheet →
  • kubectl api-resources --sort-by=name -o wideKubernetesEvery short name and resource type

    What each part does

    1. api-resourcesevery resource type: SHORTNAMES (po, svc, deploy...), API group, namespaced, verbs
    2. --sort-by=namealphabetical
    3. -o wideinclude supported verbs
    Kubernetes cheat sheet →
  • kubectl get po -l 'env in (prod,staging),tier!=frontend'KubernetesPods by set-based label selector

    What each part does

    1. -l '...'label selector
    2. env in (prod,staging)label env is one of these
    3. tier!=frontendand tier is not frontend
    Kubernetes cheat sheet →
  • kubectl get po -A -o wide --field-selector spec.nodeName=<node>KubernetesPods on a specific node

    What each part does

    1. -A -o wideall namespaces, with node column
    2. --field-selector spec.nodeName=<node>only pods scheduled on that node
    Kubernetes cheat sheet →
  • kubectl get po -o name -n <namespace>KubernetesJust the names (for scripts)

    What each part does

    1. -o nameprint type/name per line, e.g. pod/api-7d9f, ready for xargs
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get po -A -o jsonpath='{range .items[*]}{range .spec.containers[*]}{.image}{"\n"}{end}{end}' | sort | uniq -cKubernetesEvery image running in the cluster

    What each part does

    1. -o jsonpath='...'loop over pods and their containers, print each image
    2. | sort | uniq -ccount pods per image
    Kubernetes cheat sheet →
  • kubectl get po -w -n <namespace>KubernetesWatch resources change

    What each part does

    1. -wkeep printing changes (status, restarts) until Ctrl+C
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl get pods -A -o wideKubernetesPods in every namespace, with node and IP

    What each part does

    1. kubectl get podslist pods
    2. -A--all-namespaces
    3. -o wideextra columns: node, pod IP, nominated node
    Kubernetes cheat sheet →
  • kubectl get pods -A | grep <name>KubernetesFind a pod by name fragment

    What each part does

    1. kubectl get pods -Aall pods in all namespaces (columns: NAMESPACE NAME READY STATUS…)
    2. |pipe the table into grep
    3. grep <name>keep rows containing <name> (pod name, namespace or status like CrashLoopBackOff)
    Kubernetes cheat sheet →
  • kubectl get pods -A --field-selector=status.phase!=RunningKubernetesPods that are not Running

    What each part does

    1. --field-selectorfilter on object fields server-side
    2. status.phase!=Runningphase is anything except Running (Pending, Failed, Succeeded, Unknown)
    Kubernetes cheat sheet →
  • kubectl get pods -l app=<app> --show-labelsKubernetesPods with a label

    What each part does

    1. -l app=<app>--selector: label must match (use "!key" to exclude, key in (a,b) for sets)
    2. --show-labelsadd a LABELS column
    Kubernetes cheat sheet →
  • kubectl get pods -n <namespace> --sort-by=.status.containerStatuses[0].restartCountKubernetesRecently restarted pods, sorted

    What each part does

    1. --sort-by=<jsonpath>sort rows by a field of the object
    2. .status.containerStatuses[0].restartCountrestart count of the first container: crash-looping pods end up last
    Kubernetes cheat sheet →
  • kubectl get pods -o jsonpath='{.items[*].metadata.name}'KubernetesJust the pod names

    What each part does

    1. -o jsonpath=…print fields using a JSONPath template
    2. {.items[*].metadata.name}the name of every item in the list
    Kubernetes cheat sheet →
  • kubectl get pods -o custom-columns='NAME:.metadata.name,IMAGE:.spec.containers[*].image'KubernetesCustom table: pod and image

    What each part does

    1. -o custom-columns=…build your own table
    2. NAME:.metadata.namecolumn header : JSONPath of the value
    3. IMAGE:.spec.containers[*].imageimages of all containers
    Kubernetes cheat sheet →
  • kubectl api-resourcesKubernetesWhat resource types exist (and their short names)

    What each part does

    1. api-resourcesevery resource type with short name (po, svc, deploy…), API group and whether it is namespaced
    Kubernetes cheat sheet →
  • kubectl explain deployment.spec.strategyKubernetesDocs for a field

    What each part does

    1. explainbuilt-in documentation for resource fields
    2. deployment.spec.strategypath to the field you want to understand
    Kubernetes cheat sheet →
  • kubectl describe svc <service> -n <namespace>KubernetesDescribe a service

    What each part does

    1. describe svctype, selector, ports, target ports, endpoints and events
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl run dnstest --rm -it --restart=Never --image=busybox:1.36 -- nslookup <service>.<namespace>.svc.cluster.localKubernetesTest DNS from inside the cluster

    What each part does

    1. kubectl run dnstest --rm -it --restart=Neverthrowaway pod, removed when done
    2. --image=busybox:1.36small image with nslookup
    3. <service>.<namespace>.svc.cluster.locala service's full DNS name
    Kubernetes cheat sheet →
  • kubectl run curltest --rm -it --restart=Never --image=curlimages/curl -- curl -sv http://<service>.<namespace>:<port>/KubernetesCall a service from inside the cluster

    What each part does

    1. --image=curlimages/curlimage with curl
    2. http://<service>.<namespace>:<port>/service DNS name and port: tests the path pods use
    Kubernetes cheat sheet →
  • kubectl port-forward deploy/<deployment> <local-port>:<container-port> -n <namespace>KubernetesPort-forward to a deployment or pod

    What each part does

    1. deploy/<deployment>picks one pod of the deployment (also pod/<pod>, svc/<service>)
    2. <local-port>:<container-port>localhost port : port in the pod
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl proxy --port=8001KubernetesOpen a local proxy to the API server

    What each part does

    1. kubectl proxyauthenticated proxy: http://localhost:8001/api/... reaches the API, and services via /api/v1/namespaces/<ns>/services/<svc>/proxy/
    2. --port=8001local port
    Kubernetes cheat sheet →
  • kubectl get --raw='/readyz?verbose'KubernetesCheck the API server health

    What each part does

    1. get --rawcall an API path directly
    2. /readyz?verboseeach readiness check with ok/failed (also /livez)
    Kubernetes cheat sheet →

Logs & monitoring19

  • systemctl status <unit> --no-pager -lLinux & shellStatus and recent logs of a service

    What each part does

    1. systemctl status <unit>state, PID, last exit code and the last log lines
    2. --no-pagerprint directly instead of opening less
    3. -ldon't truncate long lines
    Linux & shell cheat sheet →
  • sudo systemctl enable --now <unit>Linux & shellStart at boot and start now

    What each part does

    1. enablecreate the links so the unit starts at boot
    2. --nowalso start it right away
    Linux & shell cheat sheet →
  • sudo systemctl daemon-reload && sudo systemctl restart <unit>Linux & shellReload unit files after editing them

    What each part does

    1. daemon-reloadre-read unit files (does not restart services)
    2. &&only if that worked…
    3. restart <unit>stop then start the service
    Linux & shell cheat sheet →
  • journalctl -u <unit> -f -n 100Linux & shellFollow a service log

    What each part does

    1. -u <unit>only messages from that unit
    2. -ffollow new entries
    3. -n 100start with the last 100 lines
    Linux & shell cheat sheet →
  • journalctl -p err -b --no-pagerLinux & shellErrors since boot

    What each part does

    1. -p errpriority "err" and more severe (crit, alert, emerg)
    2. -bcurrent boot only (-b -1 = previous boot)
    3. --no-pagerplain output
    Linux & shell cheat sheet →
  • journalctl -u <unit> --since "1 hour ago" --until nowLinux & shellLogs in a time window

    What each part does

    1. --sincestart time: absolute ("2026-11-20 10:00") or relative ("1 hour ago", "yesterday")
    2. --untilend time
    Linux & shell cheat sheet →
  • docker logs -f --tail 200 -t <container>DockerFollow the last 200 log lines with timestamps

    What each part does

    1. docker logs <container>the container's stdout/stderr
    2. -f--follow: keep streaming new lines
    3. --tail 200start from the last 200 lines (alias -n)
    4. -t--timestamps: prefix each line with its time
    Docker cheat sheet →
  • docker logs --since 15m <container> 2>&1 | grep -i errorDockerLogs from the last 15 minutes, errors only

    What each part does

    1. --since 15monly lines from the last 15 minutes (also 1h30m or an RFC3339 time)
    2. 2>&1merge stderr into stdout, so grep also sees error output
    3. | grep -i errorkeep lines containing "error", any case
    Docker cheat sheet →
  • docker exec -it <container> shDockerOpen a shell inside a running container

    What each part does

    1. docker exec <container>run a command in a running container
    2. -i--interactive: keep stdin open
    3. -t--tty: allocate a terminal
    4. shthe command to run (use bash if the image has it)
    Docker cheat sheet →
  • docker exec -e <KEY>=<value> -w <dir> <container> <cmd>DockerRun a one-off command with env and workdir

    What each part does

    1. -e <KEY>=<value>set an environment variable for this command only
    2. -w <dir>working directory inside the container
    3. <cmd>command to run; wrap chains as sh -c "a && b"
    Docker cheat sheet →
  • docker cp <container>:<path> ./ ; docker cp ./<file> <container>:<path>DockerCopy a file out of / into a container

    What each part does

    1. docker cp <container>:<path> ./container → current host directory
    2. ;then
    3. docker cp ./<file> <container>:<path>host → container
    Docker cheat sheet →
  • kubectl describe pod <pod> -n <namespace>KubernetesWhy is a pod not starting?

    What each part does

    1. describe pod <pod>status, conditions, container states (Last State / Exit Code) and events at the bottom
    2. -n <namespace>namespace of the pod

    Tip Look for ImagePullBackOff, FailedScheduling, OOMKilled, probe failures in Events.

    Kubernetes cheat sheet →
  • kubectl get events -n <namespace> --sort-by=.metadata.creationTimestampKubernetesRecent events, newest last

    What each part does

    1. get eventscluster events (scheduling, pulls, kills, probe failures)
    2. --sort-by=.metadata.creationTimestampoldest → newest
    Kubernetes cheat sheet →
  • kubectl events -n <namespace> --types=WarningKubernetesOnly warning events

    What each part does

    1. kubectl eventsnewer events subcommand
    2. --types=Warningonly Warning-type events
    Kubernetes cheat sheet →
  • kubectl logs -f <pod> -n <namespace> --tail=200KubernetesFollow logs of a pod

    What each part does

    1. logs <pod>container's stdout/stderr
    2. -fstream new lines
    3. --tail=200start from the last 200 lines
    Kubernetes cheat sheet →
  • kubectl logs <pod> -c <container> --previousKubernetesLogs of the crashed (previous) container

    What each part does

    1. -c <container>pick a container in a multi-container pod
    2. --previouslogs of the previous instance, i.e. the one that crashed
    Kubernetes cheat sheet →
  • kubectl logs -l app=<app> --all-containers --prefix -fKubernetesLogs from all pods with a label

    What each part does

    1. -l app=<app>every pod matching the label
    2. --all-containersall containers in each pod
    3. --prefixprefix lines with pod/container name
    4. -ffollow
    Kubernetes cheat sheet →
  • kubectl logs deploy/<deployment> --since=1h | grep -i errorKubernetesGrep logs for errors

    What each part does

    1. deploy/<deployment>logs from one pod of the deployment
    2. --since=1honly the last hour
    3. | grep -i errorkeep lines with "error", any case
    Kubernetes cheat sheet →
  • kubectl top pod -n <namespace> --sort-by=memory --containersKubernetesCPU / memory usage

    What each part does

    1. top podlive usage (needs metrics-server)
    2. --sort-by=memoryhighest memory first (or cpu)
    3. --containersper container instead of per pod
    Kubernetes cheat sheet →

Shell in, port-forward & copy4

  • kubectl exec -it <pod> -n <namespace> -- shKubernetesShell into a pod

    What each part does

    1. exec <pod>run a command in a container of the pod
    2. -itinteractive stdin + terminal
    3. --everything after this is the command, not kubectl flags
    4. shthe shell (bash if available)
    Kubernetes cheat sheet →
  • kubectl port-forward svc/<service> <local-port>:<service-port> -n <namespace>KubernetesReach a service from your laptop

    What each part does

    1. port-forwardtunnel a local port into the cluster
    2. svc/<service>target a service (or pod/<pod>, deploy/<name>)
    3. <local-port>:<service-port>listen on localhost:<local-port>, forward to <service-port>
    Kubernetes cheat sheet →
  • kubectl cp <namespace>/<pod>:<path> ./<file>KubernetesCopy files out of / into a pod

    What each part does

    1. cpcopy files (needs tar inside the container)
    2. <namespace>/<pod>:<path>source in the pod; swap the arguments to copy into the pod
    Kubernetes cheat sheet →
  • kubectl debug <pod> -it --image=busybox:1.36 --target=<container>KubernetesAttach a debug container to a pod

    What each part does

    1. debug <pod>add an ephemeral debug container
    2. -itinteractive terminal
    3. --image=busybox:1.36image with the tools you need
    4. --target=<container>share that container's process namespace
    Kubernetes cheat sheet →

Build, run, deploy & roll back128

  • docker run -d --name <name> -p <host-port>:<container-port> <image>:<tag>DockerRun a service in the background with a port and a name

    What each part does

    1. docker runcreate and start a container
    2. -d--detach: run in the background and print the ID
    3. --name <name>give it a fixed name instead of a random one
    4. -p <host-port>:<container-port>publish a container port on the host (binds all interfaces; use 127.0.0.1:<host-port>:… for local only)
    5. <image>:<tag>image to run (pin a tag, avoid latest)
    Docker cheat sheet →
  • docker run -it --rm <image> shDockerThrow-away interactive container

    What each part does

    1. -itinteractive + terminal
    2. --rmdelete the container (and anonymous volumes) when it exits
    3. shcommand to run instead of the image default
    Docker cheat sheet →
  • docker run -d -e <KEY>=<value> --env-file .env -v <host-path>:<container-path>:ro -m 512m --cpus 1 --restart unless-stopped <image>DockerEnv vars, volume and limits

    What each part does

    1. -e <KEY>=<value>set one environment variable
    2. --env-file .envload KEY=value lines from a file
    3. -v <host-path>:<container-path>:robind-mount a host folder, read-only
    4. -m 512mmemory limit (exceeding it → OOM kill, exit 137)
    5. --cpus 1at most one CPU worth of time
    6. --restart unless-stoppedrestart automatically unless you stopped it yourself
    Docker cheat sheet →
  • docker build -t <registry>/<image>:<tag> -f <Dockerfile> .DockerBuild and tag an image

    What each part does

    1. docker buildbuild an image (BuildKit)
    2. -t <registry>/<image>:<tag>name and tag for the result
    3. -f <Dockerfile>which Dockerfile (default ./Dockerfile)
    4. .build context: the folder sent to the builder (.dockerignore trims it)
    Docker cheat sheet →
  • docker build --no-cache --pull --target <stage> --build-arg <KEY>=<value> -t <image>:<tag> .DockerClean rebuild of one stage with a build arg

    What each part does

    1. --no-cacheignore cached layers
    2. --pullalways check for a newer base image
    3. --target <stage>stop at a named stage of a multi-stage Dockerfile
    4. --build-arg <KEY>=<value>value for an ARG in the Dockerfile
    Docker cheat sheet →
  • docker tag <image>:<tag> <registry>/<image>:<tag> && docker push <registry>/<image>:<tag>DockerTag and push to a registry

    What each part does

    1. docker tag <src> <target>add another name to an existing image
    2. &&only if tagging worked
    3. docker push <target>upload it (run docker login <registry> first)
    Docker cheat sheet →
  • docker history --no-trunc <image>DockerImage layers and what created them

    What each part does

    1. docker historyone row per layer with its size
    2. --no-truncshow the full command that created each layer
    Docker cheat sheet →
  • docker compose up -d --buildDockerBuild and start everything in the background

    What each part does

    1. docker composeCompose v2 (plugin; not the old docker-compose binary)
    2. upcreate and start the services
    3. -ddetached
    4. --buildbuild images before starting
    Docker cheat sheet →
  • docker compose up -d --force-recreate --remove-orphans --waitDockerRecreate cleanly and wait until healthy

    What each part does

    1. --force-recreaterecreate containers even if nothing changed
    2. --remove-orphansremove containers for services no longer in the file
    3. --waitwait until services are running/healthy (implies -d)
    Docker cheat sheet →
  • docker compose logs -f --tail 100 <service>DockerFollow logs of one service

    What each part does

    1. logs <service>logs of that service (omit for all)
    2. -ffollow
    3. --tail 100start from the last 100 lines
    Docker cheat sheet →
  • docker compose exec <service> sh; docker compose run --rm <service> <cmd>DockerShell into a service / run a one-off task

    What each part does

    1. exec <service> shshell in the already-running service container
    2. run --rm <service> <cmd>start a new temporary container for a one-off command, removed afterwards
    Docker cheat sheet →
  • docker compose -f compose.yaml -f compose.prod.yaml -p <project> up -dDockerUse several compose files and a project name

    What each part does

    1. -f compose.yaml -f compose.prod.yamlmerge files in order; later files override earlier ones
    2. -p <project>project name (prefix for container/network names)
    Docker cheat sheet →
  • docker compose configDockerSee the final merged config

    What each part does

    1. configparse, merge and print the effective compose file (great for checking env substitution)
    Docker cheat sheet →
  • docker compose down -vDockerStop and remove the stack (and its volumes)Destructive

    What each part does

    1. downstop and remove containers and networks
    2. -valso remove named volumes declared in the file: deletes data
    Docker cheat sheet →
  • docker top <container>DockerProcesses running inside a container

    What each part does

    1. docker topps output for the container's processes, as seen from the host (PIDs are host PIDs)
    2. <container>name or ID
    Docker cheat sheet →
  • docker diff <container>DockerFiles changed inside a container since it started

    What each part does

    1. docker difflist files added (A), changed (C) or deleted (D) in the container's writable layer

    Tip Handy to find where an app writes data that should be in a volume.

    Docker cheat sheet →
  • docker kill -s <signal> <container>DockerSend a signal to a containerCaution

    What each part does

    1. docker killsend a signal to the main process (default SIGKILL)
    2. -s <signal>e.g. HUP to reload nginx config, TERM for a graceful stop
    Docker cheat sheet →
  • docker pause <container>; docker unpause <container>DockerPause and resume a container

    What each part does

    1. docker pausefreeze all processes (cgroup freezer); memory stays, no CPU used
    2. docker unpauselet them run again
    Docker cheat sheet →
  • docker wait <container>DockerWait for a container to exit and get its exit code

    What each part does

    1. docker waitblock until the container stops, then print its exit code (useful in scripts)
    Docker cheat sheet →
  • docker update --memory 1g --memory-swap 1g --cpus 1.5 --restart unless-stopped <container>DockerChange memory, CPU or restart policy of a running container

    What each part does

    1. docker updatechange settings live, no restart
    2. --memory 1g --memory-swap 1ghard memory limit; equal swap value means no extra swap
    3. --cpus 1.5at most 1.5 CPUs
    4. --restart unless-stoppednew restart policy
    Docker cheat sheet →
  • docker attach --sig-proxy=false <container>DockerAttach to a container's main process

    What each part does

    1. docker attachconnect your terminal to the main process's stdin/stdout
    2. --sig-proxy=falseso Ctrl+C doesn't kill the container; detach with Ctrl+P Ctrl+Q

    Tip Usually you want docker logs -f or docker exec instead.

    Docker cheat sheet →
  • docker events --filter container=<container> --since 30mDockerWatch Docker events live

    What each part does

    1. docker eventsstream of daemon events: create, start, die, oom, health_status, kill...
    2. --filter container=<container>only this container (also type=, event=, image=)
    3. --since 30minclude events from the last 30 minutes
    Docker cheat sheet →
  • docker commit -m "<message>" <container> <image>:<tag>DockerSave a container's current state as an image

    What each part does

    1. docker commitsnapshot the container's filesystem into a new image
    2. -m "<message>"commit message
    3. <image>:<tag>name for the new image

    Tip Good for debugging or forensics; for real images use a Dockerfile.

    Docker cheat sheet →
  • docker create --name <name> <image>:<tag>DockerCreate a container without starting it

    What each part does

    1. docker createcreate the container (pull if needed) but don't run it
    2. --name <name>its name; start later with docker start
    Docker cheat sheet →
  • docker build --build-arg <ARG>=<value> --target <stage> --no-cache -t <image>:<tag> .DockerBuild with build args, a target stage and no cache

    What each part does

    1. --build-arg <ARG>=<value>set an ARG declared in the Dockerfile (not for secrets: they stay in history)
    2. --target <stage>stop at this stage of a multi-stage build
    3. --no-cacherebuild every layer
    4. -t <image>:<tag>name the result
    5. .build context
    Docker cheat sheet →
  • docker build -f <path>/Dockerfile.prod -t <image>:<tag> .DockerUse a different Dockerfile

    What each part does

    1. -f <path>/Dockerfile.prodDockerfile to use
    2. .build context (can differ from the Dockerfile's folder)
    Docker cheat sheet →
  • docker build --secret id=npmrc,src=$HOME/.npmrc -t <image>:<tag> .DockerPass a secret to a build without leaving it in the image

    What each part does

    1. --secret id=npmrc,src=...mount a file only during the RUN step that asks for it
    2. Dockerfile sideRUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
    Docker cheat sheet →
  • docker buildx build --platform linux/amd64,linux/arm64 -t <registry>/<image>:<tag> --push .DockerBuild for several CPU architectures and push

    What each part does

    1. docker buildx buildBuildKit builder with multi-platform support
    2. --platform linux/amd64,linux/arm64build both (Intel/AMD servers and ARM like Graviton or Apple Silicon)
    3. --pushpush the multi-arch image straight to the registry
    Docker cheat sheet →
  • docker buildx ls; docker buildx create --name <builder> --useDockerList and create buildx builders

    What each part does

    1. docker buildx lsbuilders and the platforms they support
    2. docker buildx create --usenew builder (docker-container driver) and make it the default
    Docker cheat sheet →
  • docker build --progress=plain -t <image>:<tag> .DockerBuild with plain progress output (CI logs)

    What each part does

    1. --progress=plainfull, line-by-line output of every step instead of the collapsing TTY view
    Docker cheat sheet →
  • docker save -o <file>.tar <image>:<tag>DockerSave an image to a file (no registry)

    What each part does

    1. docker saveexport one or more images with all layers and tags
    2. -o <file>.tarwrite to a tar file
    Docker cheat sheet →
  • docker load -i <file>.tarDockerLoad an image from a file

    What each part does

    1. docker loadimport images saved with docker save
    2. -i <file>.tarinput file (also reads .tar.gz)
    Docker cheat sheet →
  • docker save <image>:<tag> | gzip | ssh <user>@<host> 'gunzip | docker load'DockerCopy an image to another host over SSH

    What each part does

    1. docker save <image>:<tag>stream the image as tar
    2. | gzipcompress it
    3. | ssh <user>@<host> '...'send it to the other machine
    4. gunzip | docker loadunpack and load it there
    Docker cheat sheet →
  • docker export <container> -o <file>.tarDockerExport a container's filesystem

    What each part does

    1. docker exportflatten the container's filesystem into a tar (no layers, history or metadata)
    2. -o <file>.taroutput file
    Docker cheat sheet →
  • docker initDockerGenerate a Dockerfile, compose file and .dockerignore

    What each part does

    1. docker initasks about your project (Node, Python, Go...) and writes starter Docker files
    Docker cheat sheet →
  • docker compose ps -aDockerStatus of the stack's containers

    What each part does

    1. docker compose pscontainers of this project: service, state, health, ports
    2. -ainclude stopped ones
    Docker cheat sheet →
  • docker compose restart <service>; docker compose stop <service>DockerRestart / stop one service

    What each part does

    1. restart <service>restart the container (config changes need up -d instead)
    2. stop <service>stop without removing
    Docker cheat sheet →
  • docker compose build --pull <service> && docker compose up -d <service>DockerRebuild images and recreate

    What each part does

    1. build --pullrebuild, pulling newer base images
    2. up -d <service>recreate the container with the new image
    Docker cheat sheet →
  • docker compose pullDockerPull newer images for all services

    What each part does

    1. docker compose pulldownload the image of every service; follow with up -d to use them
    Docker cheat sheet →
  • docker compose up -d --scale <service>=3DockerRun several replicas of a service

    What each part does

    1. --scale <service>=3run 3 containers of the service (don't fix a host port or container_name)
    Docker cheat sheet →
  • docker compose --profile <profile> up -dDockerStart optional services with a profile

    What each part does

    1. --profile <profile>also start services marked profiles: [<profile>], e.g. debug or tools
    Docker cheat sheet →
  • docker compose watchDockerRebuild automatically when files change

    What each part does

    1. docker compose watchsync or rebuild services on file changes, per the develop.watch section
    Docker cheat sheet →
  • docker compose top; docker compose imagesDockerProcesses and images of the stack

    What each part does

    1. docker compose topprocesses in each service container
    2. docker compose imagesimage and tag each container uses
    Docker cheat sheet →
  • docker compose cp <service>:<path> ./DockerCopy a file out of a service

    What each part does

    1. docker compose cplike docker cp, by service name
    Docker cheat sheet →
  • docker swarm init --advertise-addr <ip>DockerTurn this host into a swarm manager

    What each part does

    1. docker swarm initcreate a single-node swarm with this host as manager
    2. --advertise-addr <ip>the address other nodes use to reach it
    Docker cheat sheet →
  • docker swarm join-token workerDockerGet the join command for workers

    What each part does

    1. join-token workerprint the docker swarm join command (use manager for extra managers)
    Docker cheat sheet →
  • docker node lsDockerList nodes

    What each part does

    1. docker node lsnodes, status, availability and manager status
    Docker cheat sheet →
  • docker service create --name <service> --replicas 3 -p 80:80 <image>:<tag>DockerCreate a replicated service

    What each part does

    1. docker service createa long-running service the swarm keeps alive
    2. --replicas 33 tasks spread over the nodes
    3. -p 80:80publish through the routing mesh on every node
    Docker cheat sheet →
  • docker service ls; docker service ps <service>DockerList services and where their tasks run

    What each part does

    1. docker service lsservices with replicas running/desired
    2. docker service ps <service>each task, its node, state and errors
    Docker cheat sheet →
  • docker service scale <service>=5DockerScale a service

    What each part does

    1. scale <service>=5set the number of replicas
    Docker cheat sheet →
  • docker service update --image <image>:<new-tag> <service>; docker service rollback <service>DockerRolling update to a new image, and roll back

    What each part does

    1. service update --imagerolling replace of tasks with the new image
    2. service rollbackgo back to the previous spec
    Docker cheat sheet →
  • docker service logs -f <service>DockerLogs of all tasks of a service

    What each part does

    1. docker service logsaggregated logs from every task
    2. -ffollow
    Docker cheat sheet →
  • docker stack deploy -c compose.yaml <stack>; docker stack rm <stack>DockerDeploy and remove a stack from a compose fileCaution

    What each part does

    1. stack deploy -c compose.yaml <stack>create or update all services in the file
    2. stack rm <stack>remove the stack's services and networks
    Docker cheat sheet →
  • printf '%s' "$VALUE" | docker secret create <name> -DockerStore a secret for services

    What each part does

    1. printf '%s' "$VALUE"the secret value without a trailing newline
    2. docker secret create <name> -store it encrypted in the swarm; services mount it at /run/secrets/<name>
    Docker cheat sheet →
  • kubectl diff -f <dir> && kubectl apply -f <dir>KubernetesPreview then apply manifests

    What each part does

    1. diff -f <dir>show what would change on the server
    2. &&continue only if diff ran without error (diff exits 1 when there are changes; use ; instead if you want to apply anyway)
    3. apply -f <dir>create or update every manifest in the folder
    Kubernetes cheat sheet →
  • kubectl set image deployment/<deployment> <container>=<image>:<tag> -n <namespace>KubernetesChange the image of a deploymentCaution

    What each part does

    1. set imageupdate container images → triggers a rolling update
    2. deployment/<deployment>which deployment
    3. <container>=<image>:<tag>container name in the pod spec = new image
    Kubernetes cheat sheet →
  • kubectl rollout status deployment/<deployment> --timeout=5mKubernetesWait for the rollout to finish

    What each part does

    1. rollout statuswatch progress until done or failed
    2. --timeout=5mgive up (non-zero exit) after 5 minutes: good for CI
    Kubernetes cheat sheet →
  • kubectl rollout history deployment/<deployment>; kubectl rollout undo deployment/<deployment> --to-revision=<n>KubernetesHistory and rollbackCaution

    What each part does

    1. rollout historylist revisions
    2. rollout undogo back to the previous revision
    3. --to-revision=<n>or to a specific revision from the history
    Kubernetes cheat sheet →
  • kubectl rollout restart deployment/<deployment> -n <namespace>KubernetesRestart all pods of a deploymentCaution

    What each part does

    1. rollout restartrolling restart without changing the spec (picks up new ConfigMap/Secret values)
    Kubernetes cheat sheet →
  • kubectl scale deployment/<deployment> --replicas=<n>KubernetesScale replicasCaution

    What each part does

    1. scaleset the desired replica count
    2. --replicas=<n>new count (0 stops the app)
    Kubernetes cheat sheet →
  • kubectl create deployment <name> --image=<image> --dry-run=client -o yaml > deploy.yamlKubernetesGenerate a manifest without creating anything

    What each part does

    1. create deploymentbuild a Deployment object
    2. --dry-run=clientdon't send it to the cluster
    3. -o yamlprint it as YAML
    4. > deploy.yamlsave to a file to edit and commit
    Kubernetes cheat sheet →
  • kubectl run <name> --image=<image> --port=<port> --dry-run=client -o yaml > pod.yamlKubernetesGenerate a pod manifest

    What each part does

    1. kubectl run <name> --image=<image>a single pod (the old --generator flag is gone)
    2. --dry-run=client -o yamlprint YAML instead of creating
    3. > pod.yamlsave to edit
    Kubernetes cheat sheet →
  • kubectl expose deploy <deployment> --port=<port> --target-port=<container-port> --dry-run=client -o yaml > svc.yamlKubernetesGenerate a service manifest

    What each part does

    1. expose deploy <deployment>service selecting the deployment's pods
    2. --port / --target-portservice port / container port
    3. --dry-run=client -o yamlYAML only
    Kubernetes cheat sheet →
  • kubectl create job <job-name> --from=cronjob/<cronjob> -n <namespace>KubernetesCreate a job from a cronjob (run it now)

    What each part does

    1. create job --from=cronjob/<cronjob>one-off Job using the CronJob's template
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl create cronjob <name> --image=<image> --schedule='*/5 * * * *' -- <command>KubernetesCreate a cronjob

    What each part does

    1. --schedule='...'cron schedule
    2. -- <command>what the container runs
    Kubernetes cheat sheet →
  • kubectl get deploy <deployment> -n <namespace> -o yaml > deploy.yamlKubernetesExport an existing object as clean YAML

    What each part does

    1. -o yamlthe full object; remove status, metadata.uid, resourceVersion, managedFields before re-applying (--export no longer exists; the kubectl-neat plugin strips them)
    Kubernetes cheat sheet →
  • kubectl apply -R -f <dir>KubernetesApply a directory recursively

    What each part does

    1. -Rrecurse into subdirectories
    2. -f <dir>every manifest in it
    Kubernetes cheat sheet →
  • kubectl apply -k <overlay-dir>KubernetesApply a Kustomize overlay

    What each part does

    1. -k <dir>render kustomization.yaml and apply; kubectl kustomize <dir> just prints it
    Kubernetes cheat sheet →
  • kubectl apply --server-side -f <file>KubernetesServer-side apply

    What each part does

    1. --server-sidethe API server merges and tracks field ownership; needed for large CRDs
    Kubernetes cheat sheet →
  • kubectl replace --force -f <file>KubernetesReplace an object (delete + recreate)Caution

    What each part does

    1. replace --forcedelete and recreate: for fields that can't be changed in place
    Kubernetes cheat sheet →
  • kubectl wait --for=condition=Ready pod -l app=<app> --timeout=120s -n <namespace>KubernetesWait until pods are ready

    What each part does

    1. kubectl wait --for=condition=Readyblock until the condition is true (also --for=delete, --for=jsonpath=...)
    2. pod -l app=<app>which objects
    3. --timeout=120sfail after 2 minutes
    Kubernetes cheat sheet →
  • kubectl patch deploy <deployment> -n <namespace> -p '{"spec":{"replicas":3}}'KubernetesPatch a field (strategic merge)Caution

    What each part does

    1. patchchange part of a live object without a full manifest
    2. -p '{...}'JSON or YAML snippet merged into the object
    Kubernetes cheat sheet →
  • kubectl patch svc <service> --type=json -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'KubernetesPatch with a JSON patchCaution

    What each part does

    1. --type=jsonRFC 6902 operations: add, remove, replace at a path
    2. -p '[...]'the operations
    Kubernetes cheat sheet →
  • kubectl label po <pod> <key>=<value>; kubectl label po <pod> <key>-KubernetesAdd / remove a label

    What each part does

    1. <key>=<value>add (add --overwrite to change)
    2. <key>-remove the label; also a way to take a pod out of a service for debugging
    Kubernetes cheat sheet →
  • kubectl annotate deploy <deployment> <key>='<value>' --overwriteKubernetesAdd an annotation

    What each part does

    1. annotatenon-identifying metadata read by tools
    2. --overwritereplace an existing value
    Kubernetes cheat sheet →
  • kubectl autoscale deploy <deployment> --min=2 --max=10 --cpu-percent=80KubernetesAutoscale a deployment

    What each part does

    1. autoscalecreate an HPA
    2. --min / --maxreplica bounds
    3. --cpu-percent=80target average CPU vs requests (pods need CPU requests)
    Kubernetes cheat sheet →
  • kubectl set resources deploy <deployment> -c <container> --requests=cpu=100m,memory=128Mi --limits=memory=256MiKubernetesSet CPU / memory requests and limitsCaution

    What each part does

    1. set resourceschange resources in the pod template (rollout follows)
    2. --requests / --limitsvalues per container
    Kubernetes cheat sheet →
  • kubectl rollout pause deploy/<deployment>; kubectl rollout resume deploy/<deployment>KubernetesPause and resume a rollout

    What each part does

    1. rollout pausestop rolling out; batch several changes
    2. rollout resumeroll them out together
    Kubernetes cheat sheet →
  • kubectl rollout history deploy/<deployment> --revision=<n>KubernetesDetails of one rollout revision

    What each part does

    1. --revision=<n>show the pod template (images, env) of that revision before undoing to it
    Kubernetes cheat sheet →
  • kubectl scale sts <statefulset> --replicas=<n> -n <namespace>KubernetesScale a StatefulSet

    What each part does

    1. scale stspods are added/removed in order (highest ordinal first on scale-down)
    Kubernetes cheat sheet →
  • terraform init -upgradeTerraform & HelmInitialise and upgrade providers

    What each part does

    1. initdownload providers/modules and configure the backend
    2. -upgradepick the newest versions allowed by the constraints
    Terraform & Helm cheat sheet →
  • terraform fmt -recursive -check && terraform validateTerraform & HelmFormat and validate

    What each part does

    1. fmt -recursiveformat .tf files in sub-folders too
    2. -checkdon't change files; exit non-zero if formatting is needed (CI)
    3. validatecheck syntax and internal consistency (no API calls)
    Terraform & Helm cheat sheet →
  • terraform plan -var-file=<env>.tfvars -out=tfplanTerraform & HelmPlan with a var file and save the plan

    What each part does

    1. plancompute what would change
    2. -var-file=<env>.tfvarsload variable values from a file (repeatable)
    3. -out=tfplansave this exact plan to apply later (contains values in clear text: keep it private)
    Terraform & Helm cheat sheet →
  • terraform apply tfplanTerraform & HelmApply exactly the reviewed planCaution

    What each part does

    1. apply tfplanapply the saved plan with no re-planning and no prompt
    Terraform & Helm cheat sheet →
  • terraform plan -input=false -no-color -detailed-exitcode -out=tfplanTerraform & HelmCI-friendly plan: did anything change?

    What each part does

    1. -input=falsenever prompt for variables
    2. -no-colorplain output for logs
    3. -detailed-exitcodeexit 0 = no changes, 1 = error, 2 = changes present
    Terraform & Helm cheat sheet →
  • terraform plan -target=<address> -out=tfplanTerraform & HelmPlan only one resource (exceptional cases)

    What each part does

    1. -target=<address>limit to that resource and its dependencies (use sparingly)
    Terraform & Helm cheat sheet →
  • terraform plan -replace=<address> -out=tfplanTerraform & HelmForce replacement of one resourceCaution

    What each part does

    1. -replace=<address>plan to destroy and recreate it (successor of taint)
    Terraform & Helm cheat sheet →
  • terraform -chdir=<dir> planTerraform & HelmRun in another folder without cd

    What each part does

    1. -chdir=<dir>global option, goes before the subcommand
    Terraform & Helm cheat sheet →
  • terraform workspace list; terraform workspace new <name>; terraform workspace select <name>Terraform & HelmList, create and switch workspaces

    What each part does

    1. workspace listworkspaces; * marks the current one
    2. workspace newnew empty state for the same code
    3. workspace selectswitch
    Terraform & Helm cheat sheet →
  • terraform plan -generate-config-out=generated.tfTerraform & HelmImport an existing resource (block, Terraform 1.5+)

    What each part does

    1. import block in codeimport { to = aws_s3_bucket.logs id = "my-logs" }
    2. -generate-config-outwrite matching resource code for you to review
    Terraform & Helm cheat sheet →
  • terraform import <address> <id>Terraform & HelmImport an existing resource (CLI)

    What each part does

    1. importrecord a real resource in state
    2. <address>resource in your code, e.g. aws_s3_bucket.logs
    3. <id>the provider's ID for it
    Terraform & Helm cheat sheet →
  • terraform plan -destroy -out=destroy.tfplanTerraform & HelmPlan destroying everythingDestructive

    What each part does

    1. -destroyplan to delete every managed resource
    2. -outsave it; apply with terraform apply destroy.tfplan
    Terraform & Helm cheat sheet →
  • terraform destroy -var-file=<env>.tfvarsTerraform & HelmDestroy everythingDestructive

    What each part does

    1. destroydelete all resources in this state (asks to confirm)
    2. -var-filesame variables as for apply
    Terraform & Helm cheat sheet →
  • terraform apply -refresh-onlyTerraform & HelmSync state with reality without changing anythingCaution

    What each part does

    1. -refresh-onlyupdate state from the real infrastructure (drift), no resource changes; replaces terraform refresh
    Terraform & Helm cheat sheet →
  • terraform consoleTerraform & HelmTry expressions interactively

    What each part does

    1. consoleREPL to evaluate expressions, functions and values from state, e.g. cidrsubnet("10.0.0.0/16", 8, 1)
    Terraform & Helm cheat sheet →
  • terraform output -json | jqTerraform & HelmOutputs as JSON

    What each part does

    1. output -jsonevery output with type and sensitive flag
    2. | jqpretty-print or pick values
    Terraform & Helm cheat sheet →
  • terraform show -json tfplan | jq '.resource_changes[] | {address, actions: .change.actions}'Terraform & HelmShow a saved plan or state in JSON

    What each part does

    1. show -json tfplanmachine-readable plan
    2. jq '...'list each resource and its actions (create, update, delete)
    Terraform & Helm cheat sheet →
  • terraform state pull > state-backup.tfstateTerraform & HelmDownload / back up the remote state

    What each part does

    1. state pullprint the current remote state
    2. > filesave a copy before risky state surgery
    Terraform & Helm cheat sheet →
  • terraform providers; terraform providers lock -platform=linux_amd64 -platform=darwin_arm64 -platform=windows_amd64Terraform & HelmProviders and lock file for all platforms

    What each part does

    1. providersprovider requirements per module
    2. providers lock -platform=...record checksums for every OS your team and CI use
    Terraform & Helm cheat sheet →
  • terraform versionTerraform & HelmVersions of Terraform and providers

    What each part does

    1. versionTerraform version and the provider versions selected in this directory
    Terraform & Helm cheat sheet →
  • terraform graph | dot -Tsvg > graph.svgTerraform & HelmDependency graph

    What each part does

    1. graphresource dependencies in DOT format
    2. dot -Tsvgrender with Graphviz
    Terraform & Helm cheat sheet →
  • terraform testTerraform & HelmRun Terraform tests

    What each part does

    1. testrun *.tftest.hcl files: plan/apply assertions against your module
    Terraform & Helm cheat sheet →
  • terraform init -upgrade -backend=falseTerraform & HelmUnlock a provider upgrade in one module

    What each part does

    1. -upgradenewest allowed provider versions
    2. -backend=falsedon't touch the backend (fast, for local checks)
    Terraform & Helm cheat sheet →
  • helm repo add <name> <url> && helm repo updateTerraform & HelmAdd a chart repo and refresh

    What each part does

    1. repo add <name> <url>register a chart repository
    2. repo updaterefresh the local index of all repos
    Terraform & Helm cheat sheet →
  • helm show values <repo>/<chart> > values.yamlTerraform & HelmLook at a chart's default values

    What each part does

    1. show valuesprint the chart's values.yaml
    2. > values.yamlsave it as a starting point
    Terraform & Helm cheat sheet →
  • helm template <release> <chart> -f <values-file> | lessTerraform & HelmRender templates locally (no cluster)

    What each part does

    1. templaterender manifests locally
    2. -f <values-file>your values (repeatable; later files win)
    3. | lesspage through the output
    Terraform & Helm cheat sheet →
  • helm upgrade --install <release> <chart> -n <namespace> --create-namespace -f <values-file> --set <key>=<value> --wait --timeout 5mTerraform & HelmInstall or upgrade in one command

    What each part does

    1. upgrade --installupgrade if the release exists, otherwise install (-i)
    2. -n <namespace>target namespace
    3. --create-namespacecreate it if missing (with --install)
    4. -f <values-file>values file
    5. --set <key>=<value>override one value on the command line (wins over -f)
    6. --waitwait until resources are ready
    7. --timeout 5mhow long to wait
    Terraform & Helm cheat sheet →
  • helm upgrade --install <release> <chart> --rollback-on-failure --timeout 5mTerraform & HelmRoll back automatically if the upgrade fails

    What each part does

    1. --rollback-on-failureHelm 4: on failure, roll back to the last good release (implies --wait)

    Tip Helm 3 calls this flag --atomic.

    Terraform & Helm cheat sheet →
  • helm history <release> -n <namespace>; helm rollback <release> <revision> -n <namespace>Terraform & HelmRelease history and rollbackCaution

    What each part does

    1. historyrevisions with status and chart/app versions
    2. rollback <release> <revision>return to that revision (omit it for the previous one)
    Terraform & Helm cheat sheet →
  • helm list -A | grep <release>Terraform & HelmFind a release in any namespace

    What each part does

    1. list -Areleases in all namespaces
    2. | grep <release>keep the matching row
    Terraform & Helm cheat sheet →
  • helm get values <release> -n <namespace> --allTerraform & HelmValues actually used by a release

    What each part does

    1. get valuesuser-supplied values of the deployed release
    2. --allinclude chart defaults too
    Terraform & Helm cheat sheet →
  • helm uninstall <release> -n <namespace>Terraform & HelmRemove a releaseDestructive

    What each part does

    1. uninstalldelete all resources of the release (PVCs may stay)
    Terraform & Helm cheat sheet →
  • helm search repo <keyword> --versions; helm search hub <keyword>Terraform & HelmSearch charts in added repos / Artifact Hub

    What each part does

    1. search repocharts in your added repos
    2. --versionsevery chart version, not only the latest
    3. search hubsearch Artifact Hub
    Terraform & Helm cheat sheet →
  • helm pull <repo>/<chart> --version <version> --untarTerraform & HelmDownload and unpack a chart

    What each part does

    1. pulldownload the chart .tgz
    2. --versionspecific chart version
    3. --untarunpack to a folder to read templates
    Terraform & Helm cheat sheet →
  • helm show chart <repo>/<chart>; helm show readme <repo>/<chart>Terraform & HelmShow a chart's metadata and README

    What each part does

    1. show chartChart.yaml: version, appVersion, dependencies
    2. show readmedocumentation
    Terraform & Helm cheat sheet →
  • helm upgrade --install <release> oci://<registry>/<path>/<chart> --version <version> -n <namespace>Terraform & HelmInstall a chart from an OCI registry

    What each part does

    1. oci://...charts stored in a container registry (no helm repo add)
    2. --versionchart version
    Terraform & Helm cheat sheet →
  • helm status <release> -n <namespace>Terraform & HelmStatus and notes of a release

    What each part does

    1. statusdeployed / failed / pending-upgrade, revision, and the chart's NOTES
    Terraform & Helm cheat sheet →
  • helm get manifest <release> -n <namespace>Terraform & HelmWhat did Helm actually deploy?

    What each part does

    1. get manifestthe rendered YAML of the current revision (--revision <n> for older)
    Terraform & Helm cheat sheet →
  • helm list -A --pending --failedTerraform & HelmReleases stuck or failed

    What each part does

    1. -Aall namespaces
    2. --pending --failedonly releases in those states (pending-upgrade blocks new upgrades)
    Terraform & Helm cheat sheet →
  • helm upgrade <release> <chart> -f <values-file> --dry-run=server --debug -n <namespace>Terraform & HelmPreview an upgrade without applying

    What each part does

    1. --dry-run=serverrender and validate against the cluster, change nothing
    2. --debugprint the rendered manifests
    Terraform & Helm cheat sheet →
  • helm diff upgrade <release> <chart> -f <values-file> -n <namespace>Terraform & HelmDiff an upgrade (helm-diff plugin)

    What each part does

    1. helm diff upgradecolored diff between the live release and what the upgrade would deploy (helm plugin install https://github.com/databus23/helm-diff)
    Terraform & Helm cheat sheet →
  • helm upgrade <release> <chart> --reuse-values --set <key>=<value>Terraform & HelmKeep current values on upgradeCaution

    What each part does

    1. --reuse-valuesstart from the last release's values
    2. --setchange only this one

    Tip Can hide new chart defaults; --reset-then-reuse-values is safer on Helm 3.14+.

    Terraform & Helm cheat sheet →
  • helm create <chart>Terraform & HelmCreate a new chart

    What each part does

    1. helm createscaffold a chart: Chart.yaml, values.yaml, templates
    Terraform & Helm cheat sheet →
  • helm lint <chart-dir> -f <values-file>Terraform & HelmLint a chart

    What each part does

    1. lintcheck the chart and rendered templates for errors and best practices
    Terraform & Helm cheat sheet →
  • helm dependency update <chart-dir>Terraform & HelmFetch chart dependencies

    What each part does

    1. dependency updatedownload the subcharts listed in Chart.yaml into charts/ and update Chart.lock
    Terraform & Helm cheat sheet →
  • helm package <chart-dir> && helm push <chart>-<version>.tgz oci://<registry>/<path>Terraform & HelmPackage and push a chart to an OCI registry

    What each part does

    1. packagebuild <chart>-<version>.tgz
    2. push ... oci://upload to the registry (helm registry login first)
    Terraform & Helm cheat sheet →
  • helm test <release> -n <namespace>Terraform & HelmRun a release's tests

    What each part does

    1. helm testrun the chart's test hook pods and report pass/fail
    Terraform & Helm cheat sheet →
  • helm plugin listTerraform & HelmInstalled Helm plugins

    What each part does

    1. plugin liste.g. diff, secrets, unittest
    Terraform & Helm cheat sheet →

Context, config, volumes & state45

  • docker volume ls; docker volume create <name>; docker volume rm <name>DockerList / create / remove volumesCaution

    What each part does

    1. volume lsnamed volumes (persistent data)
    2. volume create <name>create one (docker run -v <name>:/path also creates it)
    3. volume rm <name>delete it and its data
    Docker cheat sheet →
  • docker run -d -v <volume>:<container-path> <image>DockerMount a named volume into a container

    What each part does

    1. -v <volume>:<container-path>data written to <container-path> survives container removal
    Docker cheat sheet →
  • docker network ls; docker network create <name>DockerList / create networks

    What each part does

    1. network lsbridge, host, none + your own networks
    2. network create <name>user-defined bridge: containers on it reach each other by name
    Docker cheat sheet →
  • docker run -d --name <name> --network <network> <image>DockerRun a container on a network

    What each part does

    1. --network <network>attach to that network; other containers can reach it as http://<name>
    Docker cheat sheet →
  • docker volume inspect <volume>; docker ps -a --filter volume=<volume>DockerWhere is a volume's data and who uses it?

    What each part does

    1. docker volume inspectdriver, mountpoint on the host, labels
    2. docker ps -a --filter volume=<volume>containers using it
    Docker cheat sheet →
  • docker run --rm -v <volume>:/data:ro -v "$PWD":/backup alpine tar czf /backup/<volume>.tgz -C /data .DockerBack up a volume to a tar file

    What each part does

    1. docker run --rmthrowaway helper container
    2. -v <volume>:/data:romount the volume read-only
    3. -v "$PWD":/backupmount the current host folder
    4. alpine tar czf ... -C /data .archive the volume contents into the host folder

    Tip Stop the app first (or use its own dump tool) for consistent database backups.

    Docker cheat sheet →
  • docker run --rm -v <volume>:/data -v "$PWD":/backup alpine tar xzf /backup/<volume>.tgz -C /dataDockerRestore a volume from a tar fileCaution

    What each part does

    1. -v <volume>:/datamount the target volume read-write
    2. tar xzf ... -C /dataunpack the backup into it
    Docker cheat sheet →
  • docker volume prune -aDockerRemove unused volumesDestructive

    What each part does

    1. docker volume prunedelete volumes no container uses
    2. -ainclude named volumes (without it, only anonymous ones on Docker 23+)
    Docker cheat sheet →
  • docker network inspect <network> --format '{{json .IPAM.Config}} {{range .Containers}}{{.Name}} {{.IPv4Address}}; {{end}}'DockerInspect a network: subnet and connected containers

    What each part does

    1. docker network inspect <network>network details
    2. {{json .IPAM.Config}}subnet and gateway
    3. {{range .Containers}}...{{end}}each attached container with its IP
    Docker cheat sheet →
  • docker network connect <network> <container>; docker network disconnect <network> <container>DockerConnect / disconnect a running container to a network

    What each part does

    1. docker network connectattach to another network (containers can be on several)
    2. docker network disconnectdetach
    Docker cheat sheet →
  • docker run --rm --network host <image>; docker run --rm --network none <image>DockerRun with host or no networking

    What each part does

    1. --network hostshare the host's network stack: no port mapping, no isolation (Linux only)
    2. --network noneno network at all, only loopback
    Docker cheat sheet →
  • docker network prune -fDockerRemove unused networksCaution

    What each part does

    1. docker network prunedelete networks no container uses
    2. -fno prompt
    Docker cheat sheet →
  • docker context create <name> --docker host=ssh://<user>@<host>; docker context use <name>DockerRun docker commands against a remote host

    What each part does

    1. docker context createsave a named connection to another Docker daemon
    2. --docker host=ssh://<user>@<host>connect over SSH (no exposed TCP port needed)
    3. docker context use <name>make it the default; docker context use default to come back
    Docker cheat sheet →
  • DOCKER_HOST=ssh://<user>@<host> docker psDockerOne-off command on a remote daemon

    What each part does

    1. DOCKER_HOST=ssh://...point this one command at another daemon
    2. docker psany docker command
    Docker cheat sheet →
  • cat /etc/docker/daemon.json; journalctl -u docker -n 100 --no-pagerDockerCheck the daemon config and its logs

    What each part does

    1. /etc/docker/daemon.jsondaemon settings: log driver and rotation, registry mirrors, data-root, address pools
    2. journalctl -u dockerthe daemon's own logs (start errors, pull failures)
    Docker cheat sheet →
  • docker info --format '{{.DockerRootDir}} {{.Driver}} {{.LoggingDriver}} {{.CgroupDriver}}'DockerWhere does Docker store its data?

    What each part does

    1. {{.DockerRootDir}}data directory, usually /var/lib/docker
    2. {{.Driver}}storage driver (overlay2)
    3. {{.LoggingDriver}}default log driver (json-file, local, journald)
    4. {{.CgroupDriver}}systemd or cgroupfs
    Docker cheat sheet →
  • kubectl config current-contextKubernetesWhich cluster am I talking to?

    What each part does

    1. kubectl configwork with the kubeconfig file
    2. current-contextprint the active context (cluster + user + default namespace)
    Kubernetes cheat sheet →
  • kubectl config get-contexts; kubectl config use-context <context>KubernetesList contexts and switch

    What each part does

    1. get-contextsall contexts; * marks the active one
    2. use-context <context>make <context> the default for later commands

    Tip Check twice before running anything against prod.

    Kubernetes cheat sheet →
  • kubectl config set-context --current --namespace=<namespace>KubernetesSet the default namespace for this context

    What each part does

    1. set-contextedit a context
    2. --currentthe active one
    3. --namespace=<namespace>saved default namespace, so you can drop -n afterwards
    Kubernetes cheat sheet →
  • kubectl exec <pod> -n <namespace> -- envKubernetesPrint env vars of a running pod

    What each part does

    1. kubectl exec <pod>run in the pod (add -c <container>)
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    3. -- envprint all environment variables
    Kubernetes cheat sheet →
  • kubectl set env deploy/<deployment> --list -n <namespace>KubernetesEnv vars set on a deployment (incl. from ConfigMaps/Secrets)

    What each part does

    1. set env ... --listlist the env defined in the pod template, showing which come from configMapKeyRef / secretKeyRef
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl set env deploy/<deployment> <KEY>=<value> -n <namespace>; kubectl set env deploy/<deployment> <KEY>- -n <namespace>KubernetesSet or remove an env var (triggers a rollout)Caution

    What each part does

    1. <KEY>=<value>add or change
    2. <KEY>-trailing minus removes it
    Kubernetes cheat sheet →
  • kubectl create configmap <name> --from-literal=<key>=<value> --from-file=<path> -n <namespace>KubernetesCreate a ConfigMap from literals or a file

    What each part does

    1. create configmap <name>new ConfigMap
    2. --from-literal=<key>=<value>one key/value
    3. --from-file=<path>file content (key = file name), or a whole directory
    Kubernetes cheat sheet →
  • kubectl create secret generic <name> --from-literal=<key>=<value> -n <namespace>KubernetesCreate a generic secret

    What each part does

    1. secret genericOpaque secret
    2. --from-literalvalue from the command line (lands in shell history: prefer --from-file or --from-env-file)
    Kubernetes cheat sheet →
  • kubectl create secret docker-registry <name> --docker-server=<registry> --docker-username=<user> --docker-password=<token> -n <namespace>KubernetesCreate an image pull secret

    What each part does

    1. secret docker-registrycredentials for a private registry; reference it in imagePullSecrets
    Kubernetes cheat sheet →
  • kubectl create secret tls <name> --cert=<cert>.pem --key=<key>.pem -n <namespace>KubernetesCreate a TLS secret

    What each part does

    1. secret tlskubernetes.io/tls secret used by ingresses
    2. --cert / --keyPEM certificate (with chain) and private key
    Kubernetes cheat sheet →
  • kubectl get secret <secret> -n <namespace> -o go-template='{{range $k,$v := .data}}{{$k}}={{$v | base64decode}}{{"\n"}}{{end}}'KubernetesDecode all keys of a secret

    What each part does

    1. -o go-template='...'loop over every key and base64-decode the value

    Tip Prints secrets in clear text on your screen.

    Kubernetes cheat sheet →
  • kubectl create configmap <name> --from-file=<path> --dry-run=client -o yaml | kubectl apply -f -KubernetesUpdate a ConfigMap from a file (apply-style)

    What each part does

    1. --dry-run=client -o yamlgenerate the manifest without creating
    2. | kubectl apply -f -create or update it

    Tip Pods only see new values after a restart (env) or after the kubelet syncs (mounted files).

    Kubernetes cheat sheet →
  • alias k=kubectl; source <(kubectl completion bash); complete -o default -F __start_kubectl kKubernetesShort alias with completion (bash)

    What each part does

    1. alias k=kubectltype k get po instead of kubectl get pods
    2. kubectl completion bashtab completion for resources and names (zsh: completion zsh)
    3. complete ... kmake completion work for the alias too

    Tip PowerShell: Set-Alias -Name k -Value kubectl. Put these in ~/.bashrc to keep them.

    Kubernetes cheat sheet →
  • kubectl config get-clusters; kubectl config get-usersKubernetesList clusters and users in kubeconfig

    What each part does

    1. get-clusterscluster entries
    2. get-userscredential entries
    Kubernetes cheat sheet →
  • kubectl config view --minifyKubernetesShow the current context's config only

    What each part does

    1. config viewkubeconfig contents (secrets redacted)
    2. --minifyonly what the current context uses
    Kubernetes cheat sheet →
  • KUBECONFIG=~/.kube/config:<other-config> kubectl config view --flatten > merged-configKubernetesMerge several kubeconfig files

    What each part does

    1. KUBECONFIG=a:bcolon-separated list of files kubectl reads together
    2. view --flattenone self-contained file
    Kubernetes cheat sheet →
  • kubectl config delete-context <context>KubernetesRemove a context

    What each part does

    1. delete-contextremove it from kubeconfig (cluster and user entries stay)
    Kubernetes cheat sheet →
  • kubectx <context>; kubens <namespace>KubernetesSwitch context / namespace quickly

    What each part does

    1. kubectxswitch context (plugin)
    2. kubensswitch default namespace
    Kubernetes cheat sheet →
  • kubectl explain pod.spec.containers --recursive | lessKubernetesExplain every field of a resource

    What each part does

    1. explain <path>docs for a field
    2. --recursivethe whole tree of sub-fields
    Kubernetes cheat sheet →
  • kubectl get po -A --sort-by=.metadata.creationTimestampKubernetesSort output

    What each part does

    1. --sort-by=<jsonpath>sort by any field: creation time, .status.startTime, restartCount...
    Kubernetes cheat sheet →
  • kubectl plugin list; kubectl krew listKubernetesList kubectl plugins

    What each part does

    1. plugin listkubectl-* binaries on your PATH
    2. krew listplugins installed with the krew plugin manager
    Kubernetes cheat sheet →
  • kubectl attach -it <pod> -c <container>KubernetesAttach to a running container

    What each part does

    1. attachconnect to the main process's stdin/stdout (exec starts a new process instead)
    Kubernetes cheat sheet →
  • kubectl get po -v=6KubernetesShow more detail about what kubectl does

    What each part does

    1. -v=6log the API calls kubectl makes (8 includes bodies): useful for auth and timeout problems
    Kubernetes cheat sheet →
  • terraform state list | grep <name>Terraform & HelmFind a resource in state

    What each part does

    1. state listevery resource address in the state
    2. | grep <name>keep matching addresses
    Terraform & Helm cheat sheet →
  • terraform state show <address>Terraform & HelmInspect one resource

    What each part does

    1. state show <address>all attributes stored for that resource
    Terraform & Helm cheat sheet →
  • terraform state mv <old-address> <new-address>Terraform & HelmRename/move without destroyingCaution

    What each part does

    1. state mvchange the address in state (e.g. after refactoring into a module)

    Tip Newer alternative: a moved {} block in code.

    Terraform & Helm cheat sheet →
  • terraform state rm <address>Terraform & HelmStop managing a resource (keep it in the cloud)Caution

    What each part does

    1. state rmforget the resource; the real object is NOT deleted
    Terraform & Helm cheat sheet →
  • terraform output -raw <name>Terraform & HelmRead an output for scripts

    What each part does

    1. output <name>print an output value
    2. -rawplain string without quotes (for shell variables)
    Terraform & Helm cheat sheet →
  • terraform force-unlock <lock-id>Terraform & HelmRelease a stuck lockDestructive

    What each part does

    1. force-unlock <lock-id>remove a lock left by a crashed run (ID is in the error message)

    Tip Make sure nothing else is running against this state.

    Terraform & Helm cheat sheet →

History, branches & undo48

  • git log --oneline --graph --decorate --allGitCompact graph of all branches

    What each part does

    1. git logshow commit history
    2. --onelineone line per commit: short hash + subject
    3. --graphASCII graph of branches and merges
    4. --decorateshow branch and tag names next to commits
    5. --allinclude every branch and tag, not just the current one
    Git cheat sheet →
  • git log --oneline | grep -i <text>GitFind commits whose message mentions something

    What each part does

    1. git log --onelineone commit per line
    2. | grep -i <text>keep lines containing <text>, any case

    Tip Built-in: git log --oneline --grep=<text> -i

    Git cheat sheet →
  • git log --oneline --author=<name> --since=<date> --until=<date>GitCommits by someone in a date range

    What each part does

    1. --author=<name>author matches (regex)
    2. --since / --untildate range, e.g. "2 weeks ago", 2026-11-01
    Git cheat sheet →
  • git log -S"<text>" -pGitWhen was this string added or removed?

    What each part does

    1. -S"<text>""pickaxe": commits that changed how many times <text> appears
    2. -pshow the diff of each matching commit
    Git cheat sheet →
  • git log --follow -p -- <file>GitHistory of one file, across renames

    What each part does

    1. --followkeep following the file when it was renamed
    2. -pwith diffs
    3. -- <file>"--" ends options; what follows is a path
    Git cheat sheet →
  • git blame -L <start>,<end> -- <file>GitWho changed these lines

    What each part does

    1. blamelast commit + author for every line
    2. -L <start>,<end>only that line range
    Git cheat sheet →
  • git status -sb; git diff; git diff --stagedGitWhat is staged vs not

    What each part does

    1. status -sbshort status with branch info
    2. git diffunstaged changes
    3. git diff --stagedwhat will go into the next commit
    Git cheat sheet →
  • git restore --staged <file>GitUnstage a file (keep the changes)

    What each part does

    1. restorerestore files
    2. --stagedonly the index (staging area): the change goes back to "not staged"
    Git cheat sheet →
  • git restore <file>GitDiscard local changes to a fileDestructive

    What each part does

    1. restore <file>replace the working copy with the last committed/staged version
    Git cheat sheet →
  • git reset --soft HEAD~1GitUndo the last commit, keep the changes stagedCaution

    What each part does

    1. resetmove the current branch pointer
    2. --softonly move HEAD; index and files are untouched
    3. HEAD~1one commit before HEAD
    Git cheat sheet →
  • git fetch origin && git reset --hard origin/<branch>GitThrow away local commits and changes to match the remoteDestructive

    What each part does

    1. git fetch origindownload the latest remote state
    2. &&only if that worked
    3. reset --hardmove the branch AND overwrite index + working tree
    4. origin/<branch>the remote version
    Git cheat sheet →
  • git revert <commit>GitUndo a pushed commit safely

    What each part does

    1. revert <commit>create a new commit that undoes <commit>; history is not rewritten
    Git cheat sheet →
  • git reflog -n 20GitFind a "lost" commit

    What each part does

    1. reflogevery place HEAD has been (commits, resets, rebases)
    2. -n 20last 20 entries; then git branch rescue <sha>
    Git cheat sheet →
  • git stash push -u -m "<message>"; git stash popGitPark work in progress

    What each part does

    1. stash pushsave changes and clean the working tree
    2. -uinclude untracked files
    3. -m "<message>"label it
    4. stash popapply the latest stash and drop it
    Git cheat sheet →
  • git switch -c <branch>GitCreate and switch to a branch

    What each part does

    1. switchchange branches
    2. -c <branch>create it first
    Git cheat sheet →
  • git branch --merged main | grep -vE '^\*|main' | xargs -r git branch -dGitDelete local branches already merged into mainCaution

    What each part does

    1. git branch --merged mainbranches fully merged into main
    2. grep -vE '^\*|main'-v: drop lines matching; -E: extended regex: the current branch (starts with *) and main itself
    3. xargs -r git branch -ddelete each remaining branch; -d refuses unmerged ones
    Git cheat sheet →
  • git fetch --pruneGitRemove stale remote-tracking branches

    What each part does

    1. fetchdownload from the remote
    2. --prunedelete local refs to branches that no longer exist on the remote
    Git cheat sheet →
  • git pull --rebase origin mainGitRebase your branch on the latest main

    What each part does

    1. pullfetch + integrate
    2. --rebasereplay your commits on top instead of creating a merge commit
    3. origin mainremote and branch
    Git cheat sheet →
  • git push -u origin <branch>GitPush a new branch and track it

    What each part does

    1. -u--set-upstream: later git push / git pull need no arguments
    Git cheat sheet →
  • git push --force-with-lease origin <branch>GitForce-push safely after a rebaseCaution

    What each part does

    1. --force-with-leaseoverwrite the remote branch only if nobody pushed since your last fetch
    Git cheat sheet →
  • git push origin --delete <branch>GitDelete a remote branchDestructive

    What each part does

    1. --deleteremove that branch on the remote
    Git cheat sheet →
  • git cherry-pick <commit>GitCopy one commit onto the current branch

    What each part does

    1. cherry-pick <commit>apply the changes of <commit> as a new commit here
    Git cheat sheet →
  • git tag -a <version> -m "<message>" && git push origin <version>GitTag a release and push it

    What each part does

    1. tag -a <version>annotated tag (has author, date, message)
    2. -m "<message>"tag message
    3. git push origin <version>tags are not pushed with branches; push it explicitly
    Git cheat sheet →
  • git clean -nd; git clean -fdGitPreview / remove untracked filesDestructive

    What each part does

    1. cleanremove untracked files
    2. -ndry run: list what would be removed
    3. -dinclude untracked directories
    4. -factually delete
    Git cheat sheet →
  • git rebase -i HEAD~<n>GitClean up your last commits before a PRCaution

    What each part does

    1. rebase -iinteractive: reorder, squash (s), fixup (f), reword (r) or drop commits
    2. HEAD~<n>the last n commits

    Tip Rewrites history: only for commits not yet shared, or push with --force-with-lease.

    Git cheat sheet →
  • git fetch origin && git rebase origin/mainGitRebase your branch on the latest mainCaution

    What each part does

    1. git fetch originget the newest main
    2. git rebase origin/mainreplay your commits on top of it
    Git cheat sheet →
  • git rebase --continue; git rebase --abort; git merge --abortGitContinue, skip or abort a rebase / merge

    What each part does

    1. --continueafter fixing conflicts and git add
    2. rebase --abortgo back to before the rebase
    3. merge --abortcancel a conflicted merge
    Git cheat sheet →
  • git commit --fixup <commit> && git rebase -i --autosquash <commit>~1GitSquash a fix into an earlier commit automaticallyCaution

    What each part does

    1. commit --fixup <commit>commit marked fixup! for that commit
    2. rebase -i --autosquashmoves and squashes it into place
    Git cheat sheet →
  • git bisect start <bad> <good>; git bisect good; git bisect bad; git bisect resetGitFind the commit that introduced a bug

    What each part does

    1. bisect start <bad> <good>binary search between a bad commit (e.g. HEAD) and a known good one
    2. bisect good / badmark each checked-out commit after testing
    3. bisect resetfinish and return to your branch

    Tip git bisect run <test-script> automates it.

    Git cheat sheet →
  • git log --oneline main..<branch>GitCommits on a branch that aren't on main

    What each part does

    1. main..<branch>reachable from branch but not from main
    Git cheat sheet →
  • git diff main...<branch> --statGitCompare two branches

    What each part does

    1. main...<branch>changes on branch since it split from main (three dots)
    2. --statfiles and line counts only
    Git cheat sheet →
  • git shortlog -sn --no-mergesGitWho committed how much

    What each part does

    1. shortlog -s -ncommit count per author, sorted
    2. --no-mergesskip merge commits
    Git cheat sheet →
  • git grep -n '<text>' <commit-or-branch>GitSearch the code in any commit

    What each part does

    1. git grep -nfast search of tracked files with line numbers
    2. <commit-or-branch>search that version instead of the working tree
    Git cheat sheet →
  • git restore --source=<commit> -- <file>GitRestore a file from another commit or branchCaution

    What each part does

    1. --source=<commit>take the file's content from that commit
    2. -- <file>only that path
    Git cheat sheet →
  • git describe --tags --alwaysGitDescribe the current version from tags

    What each part does

    1. describe --tagsnearest tag + commits since + short SHA, e.g. v1.4.0-3-g4f2a9c1
    2. --alwaysfall back to the SHA if no tag
    Git cheat sheet →
  • git filter-repo --invert-paths --path <file>GitRemove a file from all history (leaked secret)Destructive

    What each part does

    1. git filter-reporewrite the whole history (separate tool, replaces filter-branch)
    2. --invert-paths --path <file>drop that file everywhere

    Tip Rotate the secret first; everyone must re-clone after the force push.

    Git cheat sheet →
  • git stash list; git stash show -p stash@{1}; git stash apply stash@{1}; git stash drop stash@{1}GitList, show, apply and drop stashes

    What each part does

    1. stash listall stashes
    2. show -pthe diff of one
    3. applyre-apply but keep it (pop removes it)
    4. dropdelete it
    Git cheat sheet →
  • git tag -l 'v1.*'; git tag -d <tag> && git push origin --delete <tag>GitList and delete tagsCaution

    What each part does

    1. tag -l 'v1.*'list matching tags
    2. tag -ddelete locally
    3. push origin --delete <tag>delete on the remote
    Git cheat sheet →
  • git push --tagsGitPush all tags

    What each part does

    1. --tagspush every local tag (git push --follow-tags pushes only annotated ones for pushed commits)
    Git cheat sheet →
  • git remote set-url origin <url>GitChange a remote's URL (HTTPS to SSH, moved repo)

    What each part does

    1. remote set-url originpoint origin at a new URL
    Git cheat sheet →
  • git worktree add ../<dir> <branch>; git worktree list; git worktree remove ../<dir>GitWork on two branches at once

    What each part does

    1. worktree addcheck out another branch in a second folder, sharing the same repo
    2. list / removesee and clean up worktrees
    Git cheat sheet →
  • git clone --recurse-submodules <url>; git submodule update --init --recursiveGitClone with submodules / update them

    What each part does

    1. --recurse-submodulesalso clone nested repos
    2. submodule update --init --recursivefetch submodules in an existing clone
    Git cheat sheet →
  • git ls-files | grep <pattern>GitWhich files does git track?

    What each part does

    1. ls-filestracked files
    2. | grepfilter
    Git cheat sheet →
  • git check-ignore -v <file>GitWhy is this file ignored?

    What each part does

    1. check-ignore -vthe .gitignore file and line that ignores it
    Git cheat sheet →
  • git config --list --show-originGitSee all config and where it comes from

    What each part does

    1. --listevery setting
    2. --show-originwhich file set it (system, global, repo)
    Git cheat sheet →
  • git config --global alias.lg "log --oneline --graph --decorate --all"GitCreate a git alias

    What each part does

    1. alias.lgnew command git lg
    2. "log ..."what it expands to
    Git cheat sheet →
  • git archive --format=zip -o <file>.zip <commit-or-tag>GitMake a zip of a commit without .git

    What each part does

    1. git archiveexport the tracked files of that version
    2. --format=zip -ooutput format and file
    Git cheat sheet →
  • git switch -GitSwitch back to the previous branch

    What each part does

    1. -the branch you were on before (like cd -)
    Git cheat sheet →

Clean up16

  • docker system dfDockerHow much space Docker uses

    What each part does

    1. docker system dfspace used by images, containers, volumes and build cache, plus how much is reclaimable
    Docker cheat sheet →
  • docker ps -q | xargs -r docker stopDockerStop all running containersCaution

    What each part does

    1. docker ps -qIDs of running containers
    2. |pipe them to xargs
    3. xargs -rpass them as arguments; -r: don't run if the list is empty
    4. docker stopstop each one gracefully (SIGTERM, then SIGKILL after 10s)
    Docker cheat sheet →
  • docker ps -aq --filter status=exited | xargs -r docker rmDockerRemove all exited containersCaution

    What each part does

    1. -aqall containers, IDs only
    2. --filter status=exitedonly exited ones
    3. xargs -r docker rmremove them

    Tip Same result: docker container prune

    Docker cheat sheet →
  • docker system prune -f --filter "until=24h"DockerRemove unused data older than a dayCaution

    What each part does

    1. docker system pruneremove stopped containers, unused networks, dangling images and build cache
    2. -f--force: no confirmation prompt
    3. --filter "until=24h"only things older than 24 hours
    Docker cheat sheet →
  • docker system prune -a --volumesDockerRemove everything unused, including volumesDestructive

    What each part does

    1. -a--all: also every image not used by a container (not just dangling)
    2. --volumesalso unused volumes: this deletes data
    Docker cheat sheet →
  • docker builder prune -af --filter "until=24h"DockerRemove build cache onlyCaution

    What each part does

    1. docker builder pruneremove BuildKit build cache (image prune does not touch it)
    2. -aall cache, not only dangling
    3. -fno prompt
    4. --filter "until=24h"keep the last day of cache
    Docker cheat sheet →
  • kubectl delete pods -n <namespace> --field-selector=status.phase=FailedKubernetesDelete failed / evicted podsDestructive

    What each part does

    1. delete podsdelete pods…
    2. --field-selector=status.phase=Failed…but only those in phase Failed (includes Evicted)
    Kubernetes cheat sheet →
  • kubectl get pods -n <namespace> --no-headers | awk '/<pattern>/{print $1}' | xargs -r kubectl delete pod -n <namespace>KubernetesDelete pods whose name matches a patternDestructive

    What each part does

    1. --no-headersdrop the header row so only data lines go through
    2. awk '/<pattern>/{print $1}'for lines matching <pattern>, print column 1 (the pod name)
    3. xargs -r kubectl delete poddelete each name; -r: skip if nothing matched
    Kubernetes cheat sheet →
  • kubectl drain <node> --ignore-daemonsets --delete-emptydir-data; kubectl uncordon <node>KubernetesTake a node out for maintenance and backCaution

    What each part does

    1. drain <node>cordon the node and evict its pods
    2. --ignore-daemonsetsdon't fail on DaemonSet pods (they stay)
    3. --delete-emptydir-dataallow evicting pods that use emptyDir (that data is lost)
    4. uncordon <node>make it schedulable again
    Kubernetes cheat sheet →
  • kubectl top node; kubectl describe node <node>KubernetesNode usage and details

    What each part does

    1. top nodeCPU/memory per node
    2. describe nodecapacity, allocatable, conditions (DiskPressure, MemoryPressure) and pods on it
    Kubernetes cheat sheet →
  • kubectl delete po <pod> -n <namespace>KubernetesDelete a pod (its controller recreates it)Caution

    What each part does

    1. delete po <pod>graceful delete; a Deployment/StatefulSet makes a new one
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
    Kubernetes cheat sheet →
  • kubectl delete po <pod> -n <namespace> --grace-period=0 --forceKubernetesForce delete a stuck podDestructive

    What each part does

    1. --grace-period=0 --forceremove from the API immediately without waiting for the kubelet (pod stuck in Terminating)

    Tip The container may still be running on the node; for StatefulSets this can cause two pods with the same identity.

    Kubernetes cheat sheet →
  • kubectl delete po,svc -l app=<app> -n <namespace>KubernetesDelete by labelDestructive

    What each part does

    1. po,svcseveral types at once
    2. -l app=<app>everything with that label
    Kubernetes cheat sheet →
  • kubectl delete <type> <name> -n <namespace>KubernetesDelete a resource by type and nameDestructive

    What each part does

    1. <type> <name>e.g. deploy api, svc api, cm app-config, rs api-7d9f
    Kubernetes cheat sheet →
  • kubectl delete all --all -n <namespace>KubernetesDelete everything in a namespace (keep the namespace)Destructive

    What each part does

    1. allpods, services, deployments, replicasets, statefulsets, jobs (not configmaps, secrets, PVCs)
    2. --allevery object of those types
    Kubernetes cheat sheet →
  • kubectl delete ns <namespace>KubernetesDelete a namespace and everything in itDestructive

    What each part does

    1. delete nsremoves the namespace and all objects in it, including PVCs and secrets
    Kubernetes cheat sheet →

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…