I recently learned about the Bash built-in fc. It is a great tool that enables you to edit and re-execute commands from your bash history.
Oftentimes there is a command in your history that instead of just grepping through the history and then re-executing as-is you’ll want to make a modification or two. With fc you can first edit it in your favorite editor and then when closing the editor fc will execute the command.
For me, vim is my editor of choice. Add the following to your .bashrc
and fc will automatically open vim for you.
export FCEDIT=vim
Then, simply run fc passing it the id of the command in your history that you want to edit and then execute.
fc 1234