When Bash Says “Permission Denied” — I Say “sudo !!”

Every so often, I find myself marching confidently into the terminal, ready to conquer the world—or at least install a database. I type out a nice, clean bash command like I own the place. But then, the terminal slaps me with a message that’s basically the digital version of, “Excuse me, who do you think you are?”

When Bash Says “Permission Denied” — I Say “sudo !!”
When Bash Says “Permission Denied” — I Say “sudo !!”
Oops! Forgot I’m not root
$ apt install mariadb
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

The terminal, in its infinite wisdom, gently reminds me that not all commands are created equal—and some require root privileges. Basically, it’s telling me, “You’re not the boss of me… unless you ask nicely with sudo.”

So now I have two options. One: sigh deeply and type the whole command again, this time with sudo in front. Two: question my life choices for not remembering in the first place.

Trying again like a responsible sudo-er
$ sudo apt install mariadb

That works, of course. But let’s be honest—retyping an entire command you just wrote feels like washing a spoon twice. It’s annoying, it’s unnecessary, and it makes you wonder why you didn’t just remember sudo in the first place.

But there’s a better way. A smarter way. A lazier way (and I mean that in the best possible sense). Enter the glorious, the powerful, the underappreciated: !!.

Meet !! — The shell’s “Do-over” button

The double exclamation mark, also known as the “bang bang” operator (because saying that makes you sound cooler), is a bash feature that repeats your last command. It’s like a magical undo-redo hybrid, except it lets you redo what you just messed up, but properly this time.

$ apt install mariadb
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
$ echo !!
echo apt install mariadb

See what happened there? !! simply expanded to the last command I typed. This means I can now easily rerun the previous command, but with more… authority.

Fixing the permission mess like a pro
$ sudo !!
sudo apt install mariadb

And just like that, you reclaim your place as ruler of your terminal domain. No retyping. No backspacing. No accidental typos when trying to be fast. Just one glorious shortcut and you’re back in business.

Pro tip: This isn’t just for package installs. sudo !! works for any command you forgot to sudo-fy. Trying to restart a service? Access a restricted directory? Write to a protected file? If you forgot sudo, bash’s got your back with !!.

So next time you get permission-denied-ed into submission, don’t rage-type the whole thing again. Smile smugly, type sudo !!, and feel like a command-line ninja.

Because in the world of bash, efficiency isn’t just a skill—it’s a lifestyle. 😎

Leave a Comment

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

Scroll to Top