Rerun the last command with sudo !!
Got "permission denied"? Don't retype it. !! means "the previous command."
- Run a command that fails because it needs root.
- Type
sudo !!and press Enter. - The shell expands
!!to the previous command and runs it with sudo.
Tip: !$ is the last word of the previous command, handy for mkdir newdir then cd !$.
Try it now: Run
echo hello, then echo !! to see the expansion without needing sudo.Next crumbs
- 💻 Terminal & gitSearch your shell history with Ctrl+RStop pressing the up arrow 40 times. Type any part of an old command and it appears.
- 💻 Terminal & gitJump back with cd -Toggle between your last two directories, like Alt+Tab for folders.
- 💻 Terminal & gitFix your last commit with --amendForgot a file or made a typo in the message? Fold the fix into the commit you just made.