Get "PHP 8 in a Nuthshell" (Soon includes PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Quickly sudo-ing the previous command in Bash Shell

It’s just another day where I got to learn gemstone of command for Linux’s Bash shell once again.

So, you probably have run into this scenario where you forget to type sudo before your command that requires root privileges. For instance, the apt-get install command.

When you do this, the bash terminal would give you the following error.

So, to run this command with sudo what you would normally do is go back to that command and prepend sudo to it, right? Not anymore.

✨ Enter sudo !!

There’s a better and quick way to do it with just one command. Check it out.

$ sudo !!

What this command will do is it will run the previously run command with sudo so you don’t need to go back to the command and prepend or type the command all the way from scratch.

It’s just a nifty little command that can improve your workflow dramatically.

But be aware that this command only works in Bash-based shell. So, that’s the only caveat you need to know.

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?