- Posted on
- • Artificial Intelligence
Artificial Intelligence Time-Saving Linux Projects
- Author
-
-
- User
- linuxbash
- Posts by this author
- Posts by this author
-
Artificial Intelligence Time-Saving Linux Projects (Bash-First, Privacy-First)
If you spend too much time writing commit messages, digging through man pages, or triaging logs, you’re not alone. The shell is powerful—but it’s also verbose and repetitive. That’s exactly where small, local AI helpers shine: they summarize, explain, and draft text so you can act faster.
In this article you’ll build 4 practical, Bash-centric AI automations that run locally on Linux. They’re safe to adopt incrementally, easy to audit, and focused on saving minutes every day.
- What you’ll get:
- Actionable scripts you can paste and use immediately
- Local-first approach (via Ollama) for privacy and control
- Install steps for apt, dnf, and zypper
- Real-world examples and a simple way to swap in any AI backend
Why AI + Bash is a great fit
Repetitive text tasks dominate: summarization, explanation, drafting, and rewriting are where LLMs are strongest.
Local models are “good enough” for most dev-ops workflows, with no data leaving your machine.
Bash is the perfect glue: stream plain text in, get plain text out, then wire it into your workflow.
Human-in-the-loop by default: nothing runs without your approval; AI drafts, you decide.
Tip: Focus AI where context is plentiful and risk is low—summarize logs, draft commit messages, or explain commands. Avoid “let the AI run commands” patterns.
Prerequisites
You’ll need a few base tools.
Install with apt (Debian/Ubuntu):
sudo apt update
sudo apt install -y git curl jq
Install with dnf (Fedora/RHEL/CentOS Stream):
sudo dnf install -y git curl jq
Install with zypper (openSUSE):
sudo zypper refresh
sudo zypper install -y git curl jq
Add a local LLM runtime (Ollama) and pull a small, capable model:
curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3
Optional: ensure you have a local bin directory on PATH:
mkdir -p "$HOME/bin"
echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc"
source "$HOME/.bashrc"
Note: systemd-based examples assume journalctl is available (most mainstream distros).
A tiny abstraction: one function to swap AI backends
All projects below call ollama run. If you prefer to swap in any other AI CLI or API, create a single drop-in shell function:
Local (default):
AI() { ollama run "${OLLAMA_MODEL:-llama3}"; }
Cloud example (requires OPENAI_API_KEY, uses jq to extract content):
AI() {
curl -sS https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"'"$(cat)"'"}]}' \
| jq -r '.choices[0].message.content'
}
Then replace ollama run ... with AI in the scripts.
Project 1: AI-Powered Git Commit Messages (prepare-commit-msg hook)
Problem: Writing clear commit messages takes time. Solution: Use a local LLM to summarize the staged diff, then you can edit as needed.
Install the hook in your repo:
cat > .git/hooks/prepare-commit-msg <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
# Usage: Git calls this with:
# $1 = commit message file
# $2 = commit source (message, template, merge, squash, commit, etc.)
# $3 = SHA1 (for commit source "commit")
msg_file="$1"
source_type="${2:-}"
sha="${3:-}"
# Respect explicit messages and merges
if [[ "${source_type}" == "message" || "${source_type}" == "merge" || "${source_type}" == "squash" ]]; then
exit 0
fi
# Allow opting out for a single commit
if [[ "${NO_AI_COMMIT:-0}" == "1" ]]; then
exit 0
fi
# Get the staged diff (handle initial commit)
if git rev-parse --verify HEAD >/dev/null 2>&1; then
diff_content="$(git diff --staged --unified=0)"
else
diff_content="$(git diff --staged --unified=0 --no-index /dev/null . || true)"
fi
# If no changes, nothing to do
if [[ -z "${diff_content}" ]]; then
exit 0
fi
# Truncate to avoid overlong prompts
diff_trunc="$(printf "%s" "${diff_content}" | sed -n '1,300p')"
model="${OLLAMA_MODEL:-llama3}"
prompt=$'Write a concise, imperative Git commit message. Use this structure:\n\n<short summary under 74 chars>\n\n- key change 1\n- key change 2\n\nPrefer conventional commit style if appropriate (e.g., feat:, fix:, docs:).\nBe specific, avoid boilerplate. Use only the provided diff.\n\nStaged diff:\n'"${diff_trunc}"
# If ollama is unavailable, skip gracefully
if ! command -v ollama >/dev/null 2>&1; then
exit 0
fi
response="$(printf "%s" "${prompt}" | ollama run "${model}" || true)"
[[ -z "${response}" ]] && exit 0
# Prepend AI suggestion, preserve existing content (templates, etc.)
{
printf "%s\n\n" "${response}"
cat "${msg_file}"
} > "${msg_file}.tmp"
mv "${msg_file}.tmp" "${msg_file}"
EOF
chmod +x .git/hooks/prepare-commit-msg
Try it:
git add .
git commit
You’ll get a draft message you can edit before saving.
Tips:
Temporarily skip with
NO_AI_COMMIT=1 git commit.Set a different model:
export OLLAMA_MODEL=llama3.
Project 2: “aiman” — Ask Questions About a Command’s Man Page
Problem: Man pages are thorough, but dense. Solution: Pipe the man page to a local model and ask focused questions, with answers grounded in the page content.
Create the aiman tool:
cat > "$HOME/bin/aiman" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: aiman <command> [question]"
exit 1
fi
cmd="$1"; shift || true
question="${*:-Teach me the most common usage with practical examples.}"
# Extract and trim the man page content
ctx="$(man -P cat "${cmd}" 2>/dev/null | col -b | head -c 120000 || true)"
if [[ -z "${ctx}" ]]; then
echo "No man page found for '${cmd}'."
exit 2
fi
model="${OLLAMA_MODEL:-llama3}"
prompt=$'You are a Linux assistant. Answer using ONLY the provided man page. If information is missing, say you are unsure.\n\nQuestion: '"${question}"$'\n\nMan page content:\n'"${ctx}"
printf "%s" "${prompt}" | ollama run "${model}"
EOF
chmod +x "$HOME/bin/aiman"
Examples:
aiman tar "How do I exclude files and preserve permissions?"
aiman ssh "Explain ProxyJump with a simple example."
aiman find "What is the difference between -name and -path?"
Tip: The col -b filter strips backspaces and formatting from man pages for cleaner prompts.
Project 3: Hourly AI Log Summaries from journalctl (systemd user timer)
Problem: Logs are noisy; you just want “what broke and what to do.” Solution: Summarize the last hour’s warnings and errors into actionable bullets.
Create the summarizer:
cat > "$HOME/bin/ai-journal-summarize" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
OUT_DIR="${AI_LOG_SUMMARY_DIR:-$HOME/ai/log-summaries}"
mkdir -p "${OUT_DIR}"
# Collect last hour of warnings/errors (priority 0–4)
logs="$(journalctl --since "-60 min" --priority=4 -o short-iso 2>/dev/null | tail -n 5000 || true)"
[[ -z "${logs}" ]] && exit 0
model="${OLLAMA_MODEL:-llama3}"
ts="$(date -u +"%Y-%m-%dT%H%MZ")"
out_file="${OUT_DIR}/${ts}.md"
prompt=$'Summarize the following Linux journal logs (last hour) into:\n- Top 5 distinct problems (service and symptom)\n- Likely root causes per problem\n- Concrete next steps (with exact unit/file paths if present)\nBe concise and specific. Do not invent facts.\n\nLogs:\n'"${logs}"
printf "%s" "${prompt}" | ollama run "${model}" > "${out_file}"
echo "Wrote ${out_file}"
EOF
chmod +x "$HOME/bin/ai-journal-summarize"
Add a systemd user service and timer:
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/ai-journal-summarize.service <<'EOF'
[Unit]
Description=Summarize last hour of system logs with AI
[Service]
Type=oneshot
Environment=OLLAMA_MODEL=llama3
ExecStart=%h/bin/ai-journal-summarize
EOF
cat > ~/.config/systemd/user/ai-journal-summarize.timer <<'EOF'
[Unit]
Description=Hourly AI log summary
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now ai-journal-summarize.timer
systemctl --user list-timers | grep ai-journal-summarize
Open summaries in ~/ai/log-summaries/. Consider shipping to a team chat by extending the script with curl to your webhook.
Note: This relies on journalctl (systemd). On non-systemd systems, adapt to tail -F /var/log/....
Project 4: explain — Safely Understand Shell One-Liners
Problem: A mysterious one-liner shows up in chat. Is it safe? Solution: Ask a local model to break it down and assess risk before you run it.
Add a function to your shell:
cat >> "$HOME/.bashrc" <<'EOF'
explain() {
local cmd="$*"
if [[ -z "$cmd" ]]; then
echo "Usage: explain <command>"; return 2
fi
local model="${OLLAMA_MODEL:-llama3}"
local prompt=$'Explain what this command does. Break down each flag, pipes, globs, and substitutions.\nThen rate potential risk on 0–10 and suggest a safer dry-run if applicable.\n\nCommand:\n'"${cmd}"
printf "%s" "${prompt}" | ollama run "${model}"
}
EOF
source "$HOME/.bashrc"
Examples:
explain 'sudo find / -type f -name "*.key" -delete'
explain 'rsync -a --delete src/ dest/'
explain 'grep -R --exclude-dir=.git -n "token" . | cut -d: -f1 | sort -u'
Result: You get a structured explanation, a risk rating, and often a suggested dry-run or safer alternative.
Real-world usage notes
Keep prompts short and focused; cap context with tools like
head -corsed -n '1,300p'.Always review AI output. These helpers draft; you decide.
Prefer local for sensitive inputs. When using cloud APIs, scrub secrets and comply with your org’s policies.
Standardize with environment variables:
OLLAMA_MODEL=llama3AI_LOG_SUMMARY_DIR=~/ai/log-summariesNO_AI_COMMIT=1to skip the git hook
Troubleshooting
Model not found: run
ollama pull llama3again or setexport OLLAMA_MODEL=<your-model>.Permission denied: ensure scripts are executable (
chmod +x) and onPATH.Timer didn’t run: check
systemctl --user status ai-journal-summarize.timerandjournalctl --user -u ai-journal-summarize.service.
Conclusion and next steps
Small, composable AI helpers can reclaim dozens of minutes each week—without upending your stack. Start with one project:
Add the commit-message hook to your busiest repo
Use
aimanthe next time a man page overwhelms youTurn on the hourly log summaries for faster incident response
Keep
explainnearby for safer shelling
From here:
Tune prompts to your team’s style guide
Swap
ollamafor your preferred backend via theAI()functionShare your best prompts and scripts with your team (dotfiles repo FTW)
Your shell just got smarter—now make it yours.