Never Re-Type a Command Again — Use (sudo !!)
Tired of retyping commands when you forget sudo? Use sudo !! to instantly rerun the last command with elevated privileges. It’s a simple bash trick that saves time, avoids frustration, and keeps your terminal workflow smooth. A must-know for every Linux user.

Ever run a command, only to realize you forgot sudo? Instead of retyping it, use this life-saving shortcut:
$ sudo !!
Let's walk through what it does — and why you'll love it.
What Is !!?
The !!
is a bash history expansion trick that stands for:
The last command you ran.
So when you type:
$ sudo !!
It becomes:
$ sudo <your_last_command>
Real-World Example
You try to install something:
$ sudo apt install nginx
Oops — permission denied:
E: Could not open lock file /var/lib/dpkg/lock-frontend - Permission denied
Instead of retyping everything:
$ sudo !!
Boom. It reruns:
$ sudo apt install nginx
And this time — it works.
Why This Rocks
- Saves time
- Prevents typos
- Keeps your terminal flow clean
⚠ Head-up!
- This works in bash, zsh, and similar shells.
- Be cautious: !! repeats whatever your last command was — know what you’re re-running!
- To see history: run history or press the up-arrow key ↑.
We hope you found these insights useful!