- Posted on
- • Artificial Intelligence
AI-Powered Linux Cheat Sheets
- Author
-
-
- User
- linuxbash
- Posts by this author
- Posts by this author
-
AI-Powered Linux Cheat Sheets: Turn Your Terminal into a Command Coach
Ever alt-tabbed between a dozen tabs just to remember a sed flag? Or copied a risky one-liner without truly understanding it? You’re not alone. AI-powered cheat sheets let you generate, explain, and save terminal knowledge on demand—right from Bash—so you stay in the flow and build a personal, auditable knowledge base as you go.
This article shows how to:
Set up a terminal AI assistant (cloud or fully local)
Generate and explain commands safely
Capture answers into reusable Markdown cheat sheets
Browse and reuse them quickly
Why AI cheat sheets are worth it
Reduce time-to-solution: Stop searching and start asking in plain English.
Learn by doing: Ask for explanations with examples tailored to your context.
Safer commands: Preview and annotate before you run anything.
Build once, use forever: Answers become your reusable, greppable Markdown notes.
1) Pick your assistant: cloud or local
You have two great options. Choose one (or both).
Option A: Cloud (Shell-GPT, “sgpt”)
Shell-GPT is a command-line tool that asks a model (e.g., OpenAI) to suggest or explain shell commands.
Install pipx (recommended) via your package manager:
- Debian/Ubuntu (apt):
sudo apt update
sudo apt install -y pipx
pipx ensurepath
- Fedora/RHEL/CentOS (dnf):
sudo dnf install -y pipx
pipx ensurepath
- openSUSE (zypper):
sudo zypper install -y pipx
pipx ensurepath
If your repo doesn’t have pipx, you can fall back to:
python3 -m pip install --user pipx
python3 -m pipx ensurepath
Install Shell-GPT:
pipx install shell-gpt
Export your API key (example for OpenAI):
export OPENAI_API_KEY="sk-..."
Add that line to your shell profile (e.g., ~/.bashrc) to persist it.
Quick tests:
sgpt "Write a one-liner to find the 10 largest files under /var with sizes shown."
sgpt "Explain what this does: tar -xzvf backup.tar.gz -C /srv"
Tip: Don’t blindly run AI output. Always read it first.
Option B: Local/offline (Ollama + llm)
Prefer local inference? Use Ollama with the “llm” CLI. No external API keys needed.
Install Ollama:
curl -fsSL https://ollama.com/install.sh | sh
Start the service (if not started automatically):
sudo systemctl enable --now ollama
Get the llm CLI and the Ollama plugin:
pipx install llm
pipx inject llm llm-ollama
Pull a small local model (examples; pick one that fits your machine):
ollama pull qwen2.5:3b
# or
ollama pull llama3.2:3b
Ask questions through llm using Ollama:
llm -m ollama/qwen2.5:3b "Give me a safe bash one-liner to recursively replace foo with bar under ./src, printing a diff."
Note: Local models are improving fast but may be less precise than top-tier cloud models. The upside: private, offline, free to run.
2) One-minute workflows you’ll actually use
- Generate a command from plain English:
sgpt "List all processes using more than 1GB RAM with their PIDs and names."
Or locally:
llm -m ollama/qwen2.5:3b "List all processes >1GB RAM with PID and name, POSIX-compliant if possible."
- Explain a scary one-liner:
sgpt "Explain: find /var/log -type f -mtime +7 -delete"
- Compare alternatives before choosing:
sgpt "Compare rsync and rclone for syncing a directory to remote storage. Show commands and pros/cons."
- Ask for guarded commands:
sgpt "Rotate nginx logs safely with logrotate, show a minimal config and a dry-run."
- Ask for step-by-step:
sgpt "How to add a new user with restricted sudo for only systemctl start/stop of nginx, step by step."
3) Turn answers into a living cheat sheet
The point isn’t just getting an answer—it’s keeping it.
Create a simple Bash function that asks your AI, saves the response as Markdown, and shows it. This version uses Shell-GPT, but you can swap the command to use llm.
Add to your ~/.bashrc:
cheat() {
if [ $# -eq 0 ]; then
echo "Usage: cheat <topic or question>"
return 1
fi
local topic="$*"
local dir="$HOME/.cheats"
mkdir -p "$dir"
local file="$dir/${topic// /_}.md"
if [ ! -s "$file" ]; then
echo "# $topic" | tee "$file" >/dev/null
echo "" >> "$file"
sgpt "Create a concise, accurate cheat sheet for: $topic.
Use bash-friendly examples.
Prefer POSIX where sensible.
Explain risky flags.
Output in Markdown with headings and code blocks." >> "$file"
echo "" >> "$file"
echo "_Saved: $(date -Is)_" >> "$file"
fi
less -R "$file"
}
Now:
cheat "awk print selected columns"
cheat "systemctl essential commands"
cheat "iptables to nftable conversion basics"
Optional: fuzzy-search your cheats with fzf.
Install fzf:
- apt:
sudo apt update
sudo apt install -y fzf
- dnf:
sudo dnf install -y fzf
- zypper:
sudo zypper install -y fzf
Add to ~/.bashrc:
cheat-find() {
local dir="$HOME/.cheats"
[ -d "$dir" ] || { echo "No cheats saved yet."; return 1; }
local pick
pick="$(find "$dir" -type f -name '*.md' | sed "s|$dir/||" | fzf --prompt='Cheat> ' )" || return 0
less -R "$dir/$pick"
}
Usage:
cheat-find
4) Safety and reproducibility patterns
- Demand dry-runs:
sgpt "Give me an rsync command to mirror ~/Photos to /mnt/backup, with permissions preserved and a dry-run first."
- Always preview before running. This helper asks for confirmation:
run() {
echo "+ $*"
read -rp "Run this? [y/N] " ans
case "$ans" in
y|Y) eval "$@" ;;
*) echo "Aborted." ;;
esac
}
Keep context minimal. Never paste secrets, tokens, or internal URLs into prompts—especially in cloud mode.
Note model/source in your cheat files so you can trace where advice came from.
5) Real-world examples
- “Find files by content safely”:
sgpt "ripgrep to find 'DATABASE_URL' under current dir, excluding node_modules and showing context lines."
- “Quick network triage”:
sgpt "Show common ip addr/route/link commands for checking interfaces, addresses, and routes, with brief explanations."
- “Systemd crash loop debugging”:
sgpt "How to get logs and reason for a systemd service crash loop, plus a temporary override edit and revert."
- “Sed vs. awk for column edits”:
sgpt "Show sed vs awk for replacing the 3rd column with 'X' in a CSV, handling commas inside quotes carefully."
Save the best answers:
cheat "network triage with ip"
cheat "systemd crash loop debugging"
Wrap-up and next steps
You don’t have to memorize every flag. With an AI-powered workflow, you can:
Ask clear questions in your terminal
Get precise, explained commands
Save the best answers into Markdown you control
Revisit and refine them over time
Pick one setup:
Cloud: install pipx, then
pipx install shell-gptLocal:
curl -fsSL https://ollama.com/install.sh | sh+pipx install llm && pipx inject llm llm-ollama
Then add the cheat function, create your first note, and build your personal Linux command cookbook today.
If you found this useful, try converting three recurring tasks you always look up into saved cheats—and share your favorite prompts or snippets!