Subscribe to How-To Geek

Linux, Opensource, and More

Bash Shortcut to Repeat Last Command

gnu-bash.PNGGnu's Bash is without a doubt the most common shell among Linux distributions and is also very common in other Unices. One great thing about Bash is that there are many shortcuts and such that make using the terminal a more pleasent experience. One of my personal favorites is !! to repeat the last used command.

!! is an easy shortcut that repeats the last used command. If you enter it on the command line by itself, it is the equivalent of pressing up+enter. However, using !! allows you to quickly add things to the command you just entered by adding them before or after the !! depending on your situation. Let's look at a few examples.

  • You forget to run a command, such as to install a package, as root. sudo !!1
  • You forget to specify a file name when opening a text file. !! file.xml
  • There is too much text to read when you display some sort of text. !! | more
  • You want to rerun a command with a(n) argument(s). !! -a
repeating-uname.png

There are many more situations where this quick shortcut can be useful. It is amazing how even the most simple things can be the best productivity boosters. Also, don't forget to try using Bash keyboard shortcuts as well.

1This idea is from the main How-To Geek site.

This article was written on 12/1/07 and tagged with: Linux

Comments (1)

  1. b05db3bdc931

    b05db3bdc931…

    b05db3bdc931ed21dbff…


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Sponsored Links
Getting Started
About How-To Geek
Popular Articles

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.