Skills › 💻 Terminal & git

Rerun the last command with sudo !!

Got "permission denied"? Don't retype it. !! means "the previous command."

⏱ 15s

  1. Run a command that fails because it needs root.
  2. Type sudo !! and press Enter.
  3. 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.

Practice in the feed →

Next crumbs

Sources