Rerun a Bash Command With Different Parameters (Advanced Bang Bang)

You probably know that you can use “bang bang” (that is: !!) to rerun your last command.
Sometimes you use it if you forgot to prefix a privileged command with sudo.

$ touch /etc/test
touch: cannot touch ‘/etc/test’: Permission denied
$ sudo !! #rerun the last command with sudo before it.

Now assume you want to rerun the last command, but want to change a parameter you passed to it.
For example

echo 1.2 && echo 2.3 && echo 4.2

You want to run the same command but with each instance of the number 2 replaced with 5.
This is how you do it

!! :gs/2/5

That’s it. Enjoy

Leave a Reply