history | tail -n 10 | awk '{$1=""; print substr($0,2)}'
get_history.sh
#!/bin/bash
# Number of last commands to retrieve
NUM_COMMANDS=${1:-10} # Default to 10 if no argument is provided
# Get last commands without numbers
history | tail -n "$NUM_COMMANDS" | awk '{$1=""; print substr($0,2)}'
Usage:
- Save the script as
get_history.sh
. - Make it executable:
chmod +x get_history.sh
- Run it:
./get_history.sh 5 # Replace 5 with any number of last commands you want