How to run the history commands quickly and easily

July 1, 2013 — Leave a comment

This is a simple command line skill for beginners how to use history commands quickly and easily.

For frequently used command with a long code, you don’t need to type all the code everytime you run this command. Just type in !n, where n is a number from your history list.

For example, following is a section of my history commands:

1262 sudo apt-key adv –keyserver –recv-keys 5044912E
1263 sudo sh -c ‘echo “deb raring main” >> /etc/apt/sources.list.d/dropbox.list’
1264 sudo apt-get update
1265 sudo apt-get install dropbox

Before cleaning the history, I can run “sudo apt-get update” command by type in:


For more:

  • !! : run the previous command.
  • !n:p : only preview command number n (will not execute the command).
  • !string : Run most recent command starting with characters in string.

I'm a freelance blogger who started using Ubuntu 5+ years ago and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me on Google Plus or email to

No Comments

Be the first to start the conversation.

Leave a Reply


Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>