DEV Community

Jason F
Jason F

Posted on

It's ok if you forget to use the sudo command

If you run Ubuntu or another Linux distro where you have to prepend a command with sudo and you're anything like me, you may from time to time forget to type sudo. Next time you forget, try typing in sudo !! and then press enter. This will prepend the previously ran command with sudo and run it.

Top comments (6)

Collapse
 
jcsh profile image
Justin Ho

GitHub logo nvbn / thefuck

Magnificent app which corrects your previous console command.

The Fuck Version Build Status Windows Build Status Coverage MIT License

The Fuck is a magnificent app, inspired by a @liamosaur tweet that corrects errors in previous console commands.

Is The Fuck too slow? Try the experimental instant mode!

gif with examples

More examples:

➜ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
➜ fuck
sudo apt-get install vim [enter/↑/↓/ctrl+c]
[sudo] password for nvbn
Reading package lists... Done
...
➜ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master


➜ fuck
git push --set-upstream origin master [enter/↑/↓/ctrl+c]
Counting objects: 9, done.
...
➜ puthon
No command 'puthon' found, did you mean
 Command 'python' from package 'python-minimal' (main)
 Command 'python' from package 'python3' (main)
Collapse
 
33nano profile image
Manyong'oments

What an interesting app. I prefer alias commands to save ample time

Collapse
 
jcsh profile image
Justin Ho

It's definitely not for everyone but the post reminded me of this app when it first launched as a meme. The beauty of our community.

Collapse
 
samuelabreu profile image
Samuel Abreu

From unix.stackexchange.com/questions/8...

alias please='sudo $(fc -ln -1)'

Collapse
 
vonheikemen profile image
Heiker

For the people who want to be extra careful when running commands with sudo, you can enable history expansion with the space key. Put this in .bashrc.

bind Space:magic-space

Now typing !!<space> will replace the !! with your last command.

If you use zsh with oh-my-zsh this is enabled by default. If you're not using oh-my-zsh, you can enable it using.

bindkey ' ' magic-space
Collapse
 
juniordevforlife profile image
Jason F

Thank you for sharing, I'll give this a try.