Correct command line typos with carets

Jul 10, '02 08:13:48AM

Contributed by: eisforian

We were arguing the most useful command line editing feature at a meeting yesterday. The winner was Ctrl-R (backwards-history-search) until someone said, "Do you guys know about carets?" He explained:

Say you type a command to list the contents of the directory /arch/Xapps/packages, but you type it incorrectly, like this:

 % ls /arch/xapps/packages
Augh! The 'x' is lowercase! Instead of retyping the command with an uppercase 'X', or hitting a bunch of keystrokes to modify it, type this and hit the return key:
 % ^xapp^Xapp
When you hit return, the shell grabs the previous command, substitutes "Xapp" for the first occurrence of "xapp" and executes the command. So typing ^xapp^Xapp and return would execute what you wanted in the first place:
 % ls /arch/Xapps/packages
Saves some typing and time when the fingers work faster than the keyboard!

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020710081348822