Quickly Fix Command Line Mistakes With The Carat (^) Symbol

For all the timesaving shortcuts we share with our fellow command line geeks here at Lifehacker, nothing kills your momentum more than correcting typos in a command. Here's a quick way to edit the previous command without typing it all out again.

Whether you've misspelled a command or want to run it again with different options, there's an easy way to find and replace text in the command line with the ^ symbol. Say you wanted to edit a file with nano, but ended up typing something else instead — like nanp. Apart from laying off the caffeine and slowing down your typing, you can easily remedy this by replacing the misspelled text with the correct text:


This tells the Terminal to run the last command, replacing nanp with nano. It doesn't work with the file paths themselves, but let's be honest — you're probably dragging those into the Terminal from Finder, Nautilus, or another graphical file manager anyway. Note also that this works with options — so, say you're an Arch Linux user and you searched for a package with the pacman -Ss command. You could easily rerun the command, removing the smaller s to install the package you searched for with:


It's a pretty handy little trick if the command itself is fairly long or tedious to type out. Hit the link to read more about find and replace tricks in Terminal, and share your own in the comments.

Correcting Command Line Mistakes [One Thing Well]


    Probably dragging???? More like probably pressing tab, or hadn't you figured that one out?

      LOL, I was thinking the same thing... When at work I wear out my delete key (Outlook), when gaming I wear out my space key and when doing stuff on my Ubuntu server, I wear out my Tab key :P

    What's wrong with pressing the up arrow then changing the one letter your misspelt?

    RTFM please.

    Firstly you could have just done:


    as this method will only replace the first instance of the replacement text.

    I guess this is why you think it doesn't apply to file paths, which of course it does!


    ls /tmi

Join the discussion!

Trending Stories Right Now