Skip to content

New To Me: The !! Shell Command

Following my recent post when I found out about the type shell command, I have another one to share with you.

Execute Previous Command: The !! command

Typing

!!

in your terminal is the same thing as pressing the up arrow once and pressing enter. It executes the previous command. Cool. But not particularly useful on it’s own. It’s actually an extra keystroke.

But you can also….

Execute Previous Command with sudo

sudo !!

will return you to a prompt with the previous command filled out. This saves you the keystrokes needed to get back to the beginning of the line to add the sudo. This will be a nice time saver for me, who is always forgetting sudo when I need it.

The history Command

After finding out about this neat sudo trick, I looked up more information and found out this is all part of the history command in bash. OpenSource.com has a post that with more examples of things you can do with the history command.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.