The !! bash trick: Insert the last used command

There are a few bash shortcuts (tricks), that make my life easier every day. One of my favourite bash tricks is !! .

!! relaunches the last used command. The benefit of the !! is that it can be combined with new arguments and options.

I often use !! when I need to exec my last used command with root priviledges.

Example: I forget to use sudo when creating a user. I will type sudo !! and the shell will replace the !! with my previously used useradd command.

$ useradd abc
$ sudo !!
sudo useradd abc
$ id abc
uid=1015(abc) gid=1015(abc) groups=1015(abc)

The !! command is usefull when you forget to use sudo for installing packages, creating users or doing other administrative tasks.

Tagged with: , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *




Subscribe to get the latest Linux news and how to guides directly on your e-mail!