How to run the history commands quickly and easily

Last updated: July 1, 2013

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 in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: