Stop blindly typing sudo when you forgot to use it
Environment & Shell Customization (Aliases/Functions/.Bashrc)
Stop blindly typing sudo when you forgot to use it
🧩 The Challenge
Everyone has typed a long, complex command, hit enter, and watched the shell laugh back with a permission denied error. It’s infuriating to hit the up arrow and hammer the left key just to prepend sudo.
💡 The Fix
You can add a quick function to your bashrc that re-runs the last command you just typed, but puts sudo in front of it so you don’t have to re-type a thing. It saves you three seconds of annoyance every single time it happens.
sudo!!() {
sudo $(fc -ln -1)
}
alias s='sudo!!'
⚙️ Why It Works
The fc command is a built-in shell tool that lets you list or edit the last command from your history. By wrapping it in a function and piping it through sudo, you effectively tell the shell to just try that last string again with root privileges.
🚀 Pro-Tip: Alias that function to s so you can literally just type s and hit enter whenever you get slapped by the shell.
Linux Tips & Tricks | © ngelinux.com | 10/17/2026
