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]