Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When one issues a command that does not exist in the terminal, it results in:

The program 'programname' is not installed. You can install it by typing:

sudo apt-get install programname

Is there any shortcut by which one does not have to retype the 'sudo apt-get install programname' line?

share|improve this question
up vote 8 down vote accepted

There is none by default, but it is not so hard to define one:

alias ii='sudo apt-get install'

You can then just call

ii !!

For more information, read man bash on aliases and history.

share|improve this answer
of course, the package isn't always called programname ... – Useless Aug 30 '12 at 16:13
@Useless: well, then you have to use the mouse, or screen and its copy mode... – choroba Aug 30 '12 at 18:50

Since the suggested command was not typed before, it won't be in the bash history. So Up Arrow or .bash_history will not help.

setting an alias for sudo apt-get install will reduce some typing but you still need to type the name of the program, particularly if the programname is differnt from the package-name.

The simplest way to "type" the command without typing is to copy the line from the terminal and paste it.

  • To copy the line, highlight sudo apt-get install programname using the mouse and press Ctrl+Shift+C.
  • To paste, make sure the cursor is at the $ prompt and press Ctrl+Shift+V.

Hope this help.

share|improve this answer
you can usually copy by just selecting, and paste by just clicking the middle mouse button, unless the defaults changed recently – Useless Aug 30 '12 at 16:14
Thanks @Useless, however, I couldn't copy by selection alone on my laptop. And it has no middle mouse button to test the paste. – user68186 Aug 30 '12 at 16:38
@user68186, try pressing left and right buttons simultaneously – vissi Aug 30 '12 at 17:41
Thanks @vissi, I am not using a mouse. On the touchpad I can press either the left or the right. – user68186 Aug 30 '12 at 18:04

Assuming the part you are trying to avoid is re-typing the last command, you can use the bash built-in "bang-bang" as a parameter for apt-get:

sudo apt-get install !!

That will replace the "!!" with the previous command you typed.

Here's a reference about other advanced shell features:

share|improve this answer

Yes, just hit the Up Arrow key on your keyboard. Hit it again to invoke the command you used before, etc.

Also, you can check out the history of your issued commands by entering:

gedit ~/.bash_history
share|improve this answer
Up-arrow does not lead to the sudo apt-get command. It leads to the previous command I typed in – deshmukh Aug 31 '12 at 14:30
I am sorry this answer wasn't helpful to you, but your title was arguably a bit ambiguous. Even though this answer might not be the one you are looking for, other users might find it helpful when searching for the use case I was referring to. – Glutanimate Aug 31 '12 at 14:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.