The !! bash command

There is a not very well known bash command that allows you to repeat the last input you typed in the shell. Behold the “!!” command. This simply allows us to retype the last input. For instance:

If I type: (to list files in the local directory):

ls -lh

and after that I type:

!!

It will repeat the “ls -lh” command.

This comes in handy when you want to script bash in a file. You can also add regex expressions. Imagine you forgot to include the hidden files in your listing, you can replace “lh” with “lha”

!!:s/lh/lha

As always, feel free to experiment. And do not forget to check the documentation.


Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *