Replace Last Command in Shell

By  on  

Whether I fat-finger a command or my MacBook Pro keyboard's keys don't want to respond like they should, I'm frequently misspelling commands.  What's more frustrating is that many of these commands are long, taking making fixing theme time-consuming.

Luckily a Twitter follower is looking out for me, providing me a quick command for fixing the misspelled command:

~ $ crul davidwalsh.name
-bash: crul: command not found
~ $ ^crul^curl
curl davidwalsh.name
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://davidwalsh.name/">here</a>.</p>
<hr>
<address>Apache Server at davidwalsh.name Port 80</address>
</body></html>

The ^ command usage above returns fixes the spelling from the previous command, executes the command, and as a bonus, adds the correct command to history.

Small tips like these and git checkout - make my command life experience so much better.  What's your favorite command line trick?

Recent Features

  • By
    Designing for Simplicity

    Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...

  • By
    9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

Incredible Demos

  • By
    WebKit Marquee CSS:  Bringin&#8217; Sexy Back

    We all joke about the days of Web yesteryear.  You remember them:  stupid animated GIFs (flames and "coming soon" images, most notably), lame counters, guestbooks, applets, etc.  Another "feature" we thought we had gotten rid of was the marquee.  The marquee was a rudimentary, javascript-like...

  • By
    Ana Tudor&#8217;s Favorite CodePen Demos

    Cocoon I love canvas, I love interactive demos and I don't think I have ever been more impressed by somebody's work than when I discovered what Tiffany Rayside has created on CodePen. So I had to start off with one of her interactive canvas pens, even though...

Discussion

  1. Hi David,

    someone pointed me to https://github.com/nvbn/thefuck/blob/master/README.md last time I complained.

    Kind regards

    André

  2. Daniel

    Hi David,

    it works fine, but does not update bash’s history

    My favorite command is CTRL-R and reuse older commands

    Abrazos, Daniel

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!