.Bash History: Correct / Repeat The Last Command With a Substitution

In a Bash shell, you can repeat the last command with a substitution using the !! command, followed by the :gs operator and the substitution expression.

For example, if you want to repeat the last command, replacing the word “old” with “new”, you can run the following command:

!!:gs/old/new

The !! command repeats the last command, and the :gs operator performs a global substitution on the repeat command, replacing “old” with “new”.

This is a convenient way to quickly repeat a previous command with slight modifications, without having to retype the entire command.

Leave a Comment