5 Ways to Save Terminal Commands for Faster DevOps
DevOps moves fast. The engineers who move fastest aren’t typing commands from memory—they’ve learned to save terminal commands and reuse them instantly.
Here are five ways to save terminal commands, from quick fixes to comprehensive solutions.
1. Supercharge Your Shell History
Your shell already saves terminal commands. Make it work harder:
# Add to .bashrc or .zshrc
# Save more history
HISTSIZE=50000
HISTFILESIZE=50000
# Save timestamps
HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
# Ignore duplicates
HISTCONTROL=ignoredups:erasedups
# Append, don't overwrite
shopt -s histappend
# Save after every command
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
Then use ctrl+r to search backwards through your history. For zsh users, plugins like zsh-autosuggestions make this even faster.
Best for: Quick recall of recent commands
2. Create a Command Snippet Library
Save terminal commands in a dedicated file or directory:
# ~/.commands/kubernetes.sh
# Get all pods in a namespace
alias kgp='kubectl get pods -n'
# Watch pods
alias kgpw='kubectl get pods -w -n'
# Get pod logs
alias kl='kubectl logs -f'
# Exec into pod
alias kex='kubectl exec -it'
Source it in your shell config:
# In .bashrc or .zshrc
source ~/.commands/kubernetes.sh
source ~/.commands/docker.sh
source ~/.commands/git.sh
Best for: Personal productivity, frequently used commands
3. Use a Terminal Command Manager
Tools like pet, navi, or tldr help you save terminal commands with descriptions:
# With pet
pet new # Add a command
pet exec # Search and run
# Example snippet
Command: kubectl get pods -n {{namespace}} -l app={{app}}
Description: Get pods by label in namespace
Best for: Teams that want searchable, parameterized commands
4. Build Shell Functions for Complex Workflows
When a single alias isn’t enough, save terminal commands as functions:
# Deploy with confirmation
deploy_api() {
local env="${1:-staging}"
echo "Deploying to $env"
echo "Current pods:"
kubectl get pods -n "$env" -l app=api
read -p "Continue? (y/n) " confirm
if [[ $confirm == "y" ]]; then
kubectl rollout restart deployment/api -n "$env"
kubectl rollout status deployment/api -n "$env"
fi
}
# Drain node safely
drain_node() {
local node="$1"
kubectl drain "$node" \
--ignore-daemonsets \
--delete-emptydir-data \
--grace-period=300
}
Best for: Multi-step operations that need logic
5. Save Terminal Commands as Executable Runbooks
The most comprehensive way to save terminal commands is as executable documentation:
# API Deployment Runbook
## Pre-deployment Checks
Verify current deployment status:
```bash
kubectl get deployment api -n production -o wide
```
Check for pending pods:
```bash
kubectl get pods -n production -l app=api --field-selector=status.phase!=Running
```
## Deploy
Trigger rolling restart:
```bash
kubectl rollout restart deployment/api -n production
```
Watch rollout progress:
```bash
kubectl rollout status deployment/api -n production
```
This approach lets you save terminal commands with full context—prerequisites, explanations, and related commands together.
Best for: Team operations, incident response, onboarding
Comparing the Approaches
| Method | Shareable | Documented | Executable | Version Controlled |
|---|---|---|---|---|
| Shell History | ❌ | ❌ | ✅ | ❌ |
| Snippet Library | Partially | ❌ | ✅ | ✅ |
| Command Manager | ✅ | ✅ | ✅ | Partially |
| Shell Functions | Partially | ❌ | ✅ | ✅ |
| Executable Runbooks | ✅ | ✅ | ✅ | ✅ |
Choose Your Strategy
For personal productivity, shell history and aliases are hard to beat. For team operations, you need something shareable and documented.
The best approach: combine them. Use aliases for daily commands, functions for complex operations, and executable runbooks for team procedures.
Stew makes that last part easy. Save terminal commands as Markdown, execute them step-by-step, share them with your team.
Join the waitlist and start building your command library.