• 6TM
  • My links
  • Tags
  • pics
  • RSS
  • Login
Filter untagged links

[OPS] Replay historyhttps://sh.6tm.es/shaare/x_nu2Q

  • Script
  • OPS
  • GNU/Linux
  • Distribution
  • TIL
  • Script
  • OPS
  • GNU/Linux
  • Distribution
  • TIL

  • replay-history.sh
#!/bin/bash

# 1. Define the number of recent commands to replay (defaults to 5 if no argument is passed)
NUM_COMMANDS=${1:-5}

# 2. Point to the primary history file and explicitly enable history tracking 
HISTFILE=~/.bash_history
set -o history

# 3. Read the history file into the current script session
history -r

# 4. Extract the commands, skipping the execution of this script itself
# We use 'tail' to get the last N commands, then loop and run them.
history | tail -n "$((NUM_COMMANDS + 1))" | head -n "$NUM_COMMANDS" | awk '{$1=""; print $0}' | while read -r cmd; do
    echo "========================================"
    echo "Replaying: $cmd"
    echo "========================================"
    eval "$cmd"
done
Permalink
October 18, 2026 at 4:49:08 PM GMT+2
QRCode
archive.org
Shaarli 111 shaares · Shaarli · The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community · Documentation · Theme : Stack · Font : DINish
Fold Fold all Expand Expand all Are you sure you want to delete this link? Are you sure you want to delete this tag? The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community