bash-fu: You forgot to sudo

Jeff Mancuso August 6th, 2008

One of the more routine annoyances of a long day in the terminal is banging out some long command that happens to operate on a file your current user doesn’t have access to.

www@webserver:~$ rm -fr /usr/lib/python2.5/site-packages/buildbot/buildbot.png<br/><br/> rm: cannot remove `/usr/lib/python2.5/site-packages/buildbot/buildbot.png': Permission denied

You declined to sudo the command because you you forgot, were feeling cautious, or were unaware of the permissions bits of the file(s) in question. Now you have to type it again, or switch gears and start up some cursor navigation to prepend your sudo.

Next time, as an easy to use alternative, try:

sudo !!

In bash, !! expands to the last run command. sudo !! sudo’s the last command. That was easy.

Tags: , ,

  • http://gul.es GUL

    Another usefull trick is type !*. That is the last command arguments (all but the first word).

    For example: www@webserver:~$ ls /usr/lib/python2.5/site-packages/buildbot/buildbot.png

    And then you want remove it, then:

    www@webserver:~$ rm !*

  • http://jeremy.visser.name/ Jeremy

    Why not press Up, Home, and type “sudo”, rather than the “!!” mojo?

  • Jeff Mancuso

    “home” doesn’t work in most terminal environments, unfortunately

  • a different Jeremy

    no, but ctl-A does. granted, i like the !! & !* methods just as well.

Grab the RSS feed
Follow ExpanDrive on Twitter Follow us on Twitter


Try ExpanDrive

If you’ve heard of SSH then you need ExpanDrive.



Try Strongspace

Awesome SFTP/rsync online storage by ExpanDrive.