How to Save Terminal Commands Permanently
You just ran a complex command that took 20 minutes to piece together. It worked. You didn’t save it. Three weeks later, you need it again.
This happens to every engineer. The solution isn’t a better memory—it’s a better system to save terminal commands.
Why Saving Terminal Commands Matters
Terminal commands are knowledge. When you don’t save terminal commands properly, you lose:
Institutional Knowledge
That kubectl one-liner to drain a node safely? The curl command with the right headers for your internal API? These are tribal knowledge that lives in your head until you leave or forget.
Time
Reconstructing commands is expensive. Finding the right flags, remembering the syntax, looking up environment-specific values—it adds up to hours per week.
Reliability
Commands typed from memory contain typos. Commands copied from unreliable sources contain errors. Saved, tested commands work.
Methods to Save Terminal Commands
1. Shell History
The simplest way to save terminal commands is your shell’s built-in history:
# Search history
history | grep "kubectl"
# Increase history size in .bashrc or .zshrc
HISTSIZE=10000
HISTFILESIZE=20000
Pros: Automatic, always available Cons: No organization, no context, lost when you switch machines
2. Personal Notes
Many engineers save terminal commands in notes apps or personal wikis:
## Restart API Pods
kubectl rollout restart deployment/api -n production
Pros: Organized, searchable, can add context Cons: Commands go stale, no execution, scattered across tools
3. Shell Aliases and Functions
For frequently used commands, aliases work well:
# In .bashrc or .zshrc
alias k="kubectl"
alias kgp="kubectl get pods"
# Functions for complex commands
restart_api() {
kubectl rollout restart deployment/api -n "$1"
}
Pros: Fast to use, always available Cons: Hard to share, no documentation, limited to simple commands
4. Script Files
Saving commands as shell scripts is a classic approach:
#!/bin/bash
# restart-api.sh
set -e
echo "Checking pod status..."
kubectl get pods -n production -l app=api
echo "Restarting..."
kubectl rollout restart deployment/api -n production
Pros: Executable, version controllable, shareable Cons: No step-by-step execution, all-or-nothing, hard to modify on the fly
5. Executable Runbooks
The modern approach: save terminal commands as executable documentation:
# Restart API
Check current pod status before restart:
```bash
kubectl get pods -n production -l app=api
```
Restart the deployment:
```bash
kubectl rollout restart deployment/api -n production
```
Pros: Human-readable, step-by-step, version controlled, shareable Cons: Needs a tool to execute
Best Practices to Save Terminal Commands
Add Context
Don’t just save the command—save why and when to use it:
## Clear Redis Cache
Use when: Users report stale data after deployments
```bash
redis-cli FLUSHDB
```
Note: This clears ALL keys. Use SCAN + DEL for selective clearing.
Include Prerequisites
Commands often have dependencies. Document them:
## Deploy Hotfix
Prerequisites:
- VPN connected
- `aws-vault` configured
- Targeting correct cluster: `kubectl config current-context`
Version Control Everything
Use Git to save terminal commands. You get history, review, and collaboration for free.
Keep Commands Close to Code
Save commands in the same repository as the code they operate on. When the code changes, the commands get updated in the same PR.
From Saving to Executing
Saving terminal commands is step one. The next step is making them executable. That’s the difference between documentation that rots and documentation that works. Learn more about how to write effective runbooks to organize your saved commands.
For more approaches, check out 5 ways to save terminal commands, our guide for SREs, or learn about saving commands as executable documentation. You can also explore the evolution of saving terminal commands to understand how these practices developed.
Stew turns your saved Markdown into runnable procedures. Write your commands once, execute them reliably every time.
Join the waitlist and start saving terminal commands the right way.