Skip to main content

DevOps and SysAdmin Workflows

These are complete, production-ready fzf workflows for day-to-day server and DevOps operations.

1. Service Manager (systemd)

# Complete systemctl manager with fzf
fservice() {
local service key

local out
out=$(systemctl list-units --type=service --all --no-pager \
| grep '\.service' \
| awk '{print $1, $2, $3, $4}' \
| fzf \
--header-lines=0 \
--ansi \
--preview 'systemctl status $(echo {} | awk "{print \$1}") --no-pager 2>/dev/null | head -30' \
--preview-window 'right:60%' \
--bind 'ctrl-/:toggle-preview' \
--expect=ctrl-r,ctrl-s,ctrl-t,ctrl-e \
--prompt '⚙ Service> ' \
--header $'Enter: status Ctrl+R: restart Ctrl+S: start\nCtrl+T: stop Ctrl+E: edit unit')

key=$(head -1 <<< "$out")
service=$(tail -1 <<< "$out" | awk '{print $1}')
[[ -z "$service" ]] && return

case "$key" in
ctrl-r) sudo systemctl restart "$service" && echo "Restarted: $service" ;;
ctrl-s) sudo systemctl start "$service" && echo "Started: $service" ;;
ctrl-t) sudo systemctl stop "$service" && echo "Stopped: $service" ;;
ctrl-e) sudo systemctl edit "$service" ;;
*) systemctl status "$service" --no-pager ;;
esac
}

2. Log Analyzer

# Interactive log browser with grep pre-filter
flogs() {
local log_dir="${1:-/var/log}"

# Pick log file
local logfile
logfile=$(find "$log_dir" -type f \( -name "*.log" -o -name "syslog" \
-o -name "auth.log" -o -name "kern.log" \) 2>/dev/null \
| fzf \
--preview 'tail -30 {}' \
--preview-window 'down:15' \
--prompt '📋 Log File> ' \
--header 'Select a log file')
[[ -z "$logfile" ]] && return

# Browse log with interactive grep
tail -10000 "$logfile" | fzf \
--tac \
--no-sort \
--preview 'echo "Context:" && echo {}' \
--preview-window 'down:3:wrap' \
--bind 'ctrl-/:toggle-preview' \
--prompt "🔍 $logfile> " \
--header $'Search log lines CTRL-/: context'
}

3. Config File Editor

# Fuzzy config file search and edit (common locations)
fconfig() {
local dirs=(/etc ~/.config ~/.ssh /opt/docker-data/apps)
local file

file=$(find "${dirs[@]}" \
\( -name "*.conf" -o -name "*.cfg" -o -name "*.ini" \
-o -name "*.yaml" -o -name "*.yml" -o -name "*.toml" \
-o -name "*.env" -o -name "nginx.conf" \
-o -name "Caddyfile" -o -name "*.json" \) \
-not -path "*/node_modules/*" \
-not -path "*/.git/*" \
2>/dev/null | fzf \
--preview 'bat --color=always --style=numbers {}' \
--preview-window 'right:60%:hidden' \
--bind 'ctrl-/:toggle-preview' \
--prompt '⚙ Config> ' \
--header 'CTRL-/: preview Enter: edit with sudo')

[[ -z "$file" ]] && return

if [ -w "$file" ]; then
${EDITOR:-vim} "$file"
else
sudo ${EDITOR:-vim} "$file"
fi
}

4. Cron Job Manager

# Browse and edit cron jobs with fzf
fcron() {
local job

{
echo "=== Current user crontab ==="
crontab -l 2>/dev/null
echo "=== /etc/cron.d ==="
ls /etc/cron.d/ 2>/dev/null
echo "=== /etc/cron.daily ==="
ls /etc/cron.daily/ 2>/dev/null
} | fzf \
--preview '
if [[ {} == /etc/cron* ]]; then
cat {}
else
echo {}
fi
' \
--prompt '⏰ Cron> ' \
--header 'Browse cron jobs' \
--bind 'enter:execute(crontab -e)'
}

5. Package Manager Helper

# fzf package browser for apt
fapt() {
local action pkg

action=$(echo -e "install\nremove\npurge\ninfo\nfiles\nsearch" \
| fzf --prompt 'Action> ' --height=8)
[[ -z "$action" ]] && return

if [[ "$action" == "install" ]]; then
pkg=$(apt-cache search '' | awk '{print $1" - "$2}' | fzf \
--preview 'apt-cache show $(echo {} | cut -d" " -f1) | head -30' \
--preview-window 'right:50%' \
--prompt '📦 Install> ' \
| cut -d' ' -f1)
[[ -n "$pkg" ]] && sudo apt install "$pkg"
else
pkg=$(dpkg -l | awk '/^ii/{print $2}' | fzf \
--preview "apt-cache show {} | head -20" \
--preview-window 'right:50%' \
--prompt "📦 ${action^}> ")
case "$action" in
remove) [[ -n "$pkg" ]] && sudo apt remove "$pkg" ;;
purge) [[ -n "$pkg" ]] && sudo apt purge "$pkg" ;;
info) [[ -n "$pkg" ]] && apt-cache show "$pkg" | less ;;
files) [[ -n "$pkg" ]] && dpkg -L "$pkg" | fzf --preview 'cat {}' ;;
esac
fi
}

6. SSH Jump Host Navigator

# Multi-hop SSH with fzf
fssh_jump() {
local bastion target

# Pick bastion host
bastion=$(grep -E "^Host " ~/.ssh/config \
| grep -v '\*' | awk '{print $2}' | fzf \
--prompt '🔐 Bastion> ' \
--header 'Select jump host')
[[ -z "$bastion" ]] && return

# Pick target host
target=$(grep -E "^Host " ~/.ssh/config \
| grep -v '\*' | awk '{print $2}' | grep -v "$bastion" | fzf \
--prompt "🎯 Target (via $bastion)> " \
--header "SSH through $bastion")
[[ -z "$target" ]] && return

ssh -J "$bastion" "$target"
}

7. Disk Usage Browser

# Interactive disk usage with fzf
fdisk() {
local dir="${1:-.}"
while true; do
local selected
selected=$(du -sh "$dir"/* 2>/dev/null | sort -rh | fzf \
--prompt "💾 $dir> " \
--preview 'du -sh {}/* 2>/dev/null | sort -rh | head -20' \
--preview-window 'right:40%' \
--header $'Enter: drill down q: quit\nSizes sorted largest first')

[[ -z "$selected" ]] && break

local target
target=$(echo "$selected" | awk '{print $2}')
if [[ -d "$target" ]]; then
dir="$target"
else
ls -lh "$target"
break
fi
done
}

What's Next