Subscribe to How-To Geek

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.

| More
This article was originally written on 12/1/07 Tagged with: Linux

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


Name:
Email:

Comments (1)

  1. Sérgio Luiz Araújo Silva

    !!:p ……… print last command (not execute)

    !rsync:p …….. view last rsync

    ^175^192 swap 175 to 192 in last command

    cd house
    command not found

    mkdir alt+.
    cd alt+.

    cp /etc/apt/sources.list{,.backup}

    tar jxvf file.tar.bz2 -C /path/to/extract/files


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to leave it on the forums instead.

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

Our Friends
Getting Started


About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
mDNSResponder.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
conhost.exe
Dpupdchk.exe Adobe_Updater.exe

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