[SOLVED] Ubuntu 21.04. Way to display list of previous n commands displayed as a selectable list?

I’m a Linux newbie. Here’s what I want. I want to type a simple command in my terminal that displays a numbered list of n previous commands. For example, I type “prevcom 20” (enter) and it displays a numbered list of my previous 20 commands. Then I type in 15 (enter) to execute the 15th command in the list.

Which app(s) adds this functionality to my terminal?

It appears that this is not possible with the “history” command.

1 Like
# Show the last 20 lines of terminal history
history | tail -n 20

# Run a previous command in history
!<history number>
# Ex: !53

For prevcom to work:

nano ~/.bashrc
# Add the following to the bottom, save and re-open the terminal.
prevcom () {
	n=$1; shift
	history | tail -n "$n" "$@"

Worked perfect. Thanks! :slightly_smiling_face: