← Back to blog

Bash REPL Productivity Tips for DevOps Engineers

· 6 min read · Stew Team
bashreplproductivitytips

Small improvements to your bash REPL workflow compound into significant time savings. These tips help you work faster in the terminal.

For shell comparisons, see our bash REPL tools comparison.

Keyboard Shortcuts

Master these and never touch the mouse.

ShortcutAction
Ctrl+ABeginning of line
Ctrl+EEnd of line
Alt+FForward one word
Alt+BBack one word
Ctrl+XXToggle between start and cursor position

Editing

ShortcutAction
Ctrl+UCut from cursor to beginning
Ctrl+KCut from cursor to end
Ctrl+WCut previous word
Alt+DCut next word
Ctrl+YPaste (yank) cut text
Ctrl+TSwap two characters
Alt+TSwap two words
Alt+UUppercase word
Alt+LLowercase word

History

ShortcutAction
Ctrl+RReverse search history
Ctrl+GCancel search
Ctrl+PPrevious command
Ctrl+NNext command
Alt+.Last argument of previous command

History Expansion

Use history without searching.

Quick References

# Repeat last command
!!

# Last command's last argument
echo !$

# Last command's first argument
echo !^

# All arguments from last command
echo !*

# Repeat command #42 from history
!42

# Repeat last command starting with 'git'
!git

# Repeat last command containing 'deploy'
!?deploy

Modifiers

# Last command, substitute text
^old^new

# Example
$ echo hello
$ ^hello^goodbye
# Runs: echo goodbye

# Get command without executing (for review)
!git:p

Argument Selection

# Previous command's second argument
!:2

# Arguments 2-4
!:2-4

# All arguments except first
!:2*

History Configuration

Make history more useful.

# ~/.bashrc

# Bigger history
HISTSIZE=50000
HISTFILESIZE=100000

# Ignore duplicates and commands starting with space
HISTCONTROL=ignoreboth

# Add timestamps
HISTTIMEFORMAT="%F %T "

# Append to history immediately
shopt -s histappend
PROMPT_COMMAND="history -a"

# Multi-line commands as single entry
shopt -s cmdhist

Command Editing

Edit complex commands more easily.

Edit in $EDITOR

# Edit current line in your editor
Ctrl+X Ctrl+E

# Opens vim/nano with your command
# Save and exit to execute

Fix Typos

# Enable spelling correction
shopt -s cdspell    # For cd
shopt -s dirspell   # For directories

Aliases and Functions

Reduce typing for common tasks.

Smart Aliases

# ~/.bashrc

# Quick navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ll='ls -lah'

# Git shortcuts
alias gs='git status'
alias gd='git diff'
alias gc='git commit'
alias gp='git push'

# Kubernetes
alias k='kubectl'
alias kgp='kubectl get pods'
alias kgs='kubectl get services'

# Safety nets
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'

Functions for Complex Tasks

# ~/.bashrc

# Create and enter directory
mkcd() {
    mkdir -p "$1" && cd "$1"
}

# Find and grep
fgrep() {
    find . -type f -name "$1" -exec grep -l "$2" {} \;
}

# Quick HTTP server
serve() {
    python3 -m http.server "${1:-8000}"
}

# Extract any archive
extract() {
    case "$1" in
        *.tar.bz2) tar xjf "$1" ;;
        *.tar.gz)  tar xzf "$1" ;;
        *.tar.xz)  tar xJf "$1" ;;
        *.zip)     unzip "$1" ;;
        *.gz)      gunzip "$1" ;;
        *.bz2)     bunzip2 "$1" ;;
        *)         echo "Unknown format: $1" ;;
    esac
}

Directory Navigation

Move around faster.

Directory Stack

# Push current directory, change to new
pushd /var/log

# Pop back to previous
popd

# View stack
dirs -v

# Go to stack position
cd ~2

CDPATH

# ~/.bashrc
export CDPATH=".:~:~/projects:~/repos"

# Now from anywhere:
cd myproject  # Finds ~/projects/myproject

Bookmarks with Aliases

# ~/.bashrc
alias proj='cd ~/projects'
alias logs='cd /var/log'
alias runbooks='cd ~/repos/runbooks'

Output Handling

Work with command output efficiently.

Paging

# Automatic paging for long output
alias less='less -R'  # Preserve colors

# Page any output
kubectl get pods -A | less

Save and View

# Save output, view later
kubectl logs pod > output.log && less output.log

# Save and display simultaneously
kubectl logs pod | tee output.log

Quick Filtering

# Last N lines
tail -20

# First N lines
head -20

# Filter
grep pattern

# Count
wc -l

# Combine
command | grep error | tail -20 | wc -l

Multi-Command Workflows

Chain commands effectively.

Conditional Execution

# Run second only if first succeeds
make && make test

# Run second only if first fails
ping -c1 host || echo "Host unreachable"

# Always run second (cleanup)
command ; cleanup

Subshells

# Isolate environment changes
(cd /tmp && rm -rf build_*)
# Still in original directory

# Capture output
result=$(curl -s api/health)

Command Substitution

# Use output as argument
vim $(fzf)

# Use output in string
echo "Today is $(date +%A)"

# Nested
echo "Host: $(hostname), IP: $(hostname -I | awk '{print $1}')"

Session Persistence

Don’t lose your REPL work.

tmux Basics

# Start named session
tmux new -s work

# Detach (session keeps running)
Ctrl+B d

# Reattach
tmux attach -t work

Save Session Output

# Record entire session
script session-$(date +%Y%m%d).log

# Work normally, then exit to stop
exit

From REPL Productivity to Team Productivity

Individual REPL efficiency is valuable. But the best workflows should be shared.

Document your optimized commands as runbooks:

# Quick Health Check

## System overview
​```bash
uptime && free -h && df -h
​```

## Process check
​```bash
ps aux --sort=-%cpu | head -10
​```

See our runbook examples for templates.

Stew: Share Your REPL Workflows

Stew turns your bash REPL expertise into executable team documentation. Your efficient command sequences become runbooks everyone can use.

Join the waitlist and multiply your productivity across your team.