If you’ve spent time in Terminal, more than likely you’ve made a typo or two—or two hundred thousand, if your typing accuracy is anything like mine! It’s one of the banes of working in Unix—after years of point-and-click, having to type sometimes long and complex commands by hand leads to inaccuracies. And, sad to say, Terminal isn’t nearly as lenient with my typos as are Word and my other text editors!
As an example, let’s say you were trying to copy OS X’s built-in webserver configuration file,
httpd.conf, to your desktop to take a look at (without worrying about damaging it). This file is located in the /etc -> httpd folder, and so your copy command would look like this in Terminal (the
is the command prompt):
$ cp /etc/httpd/httpd.conf ~/Desktop/httpd_copy.conf
But in your haste to type the command, you type
httpd. (Yes, I’m aware you can use the Tab key to auto-complete paths in Terminal—and I highly recommend you do so. For purposes of this hint, assume my Tab key has been broken in a tragic accident.) Terminal then helpfully tells you:
cp: /etc/htttpd/httpd.conf: No such file or directory
This is right, of course; there is no
folder. One way to fix this error is by pressing the up arrow, then the back arrow to move to the proper spot in the command, and finally pressing Delete at the right spot.
But here’s a potentially easier method: use the caret character (
). Immediately after you get the error in Terminal, start the next command with the caret, type in the portion of the prior command that you want to fix, type another caret, and then type the corrected version of the command. In this example, it was the three
characters that were wrong; it should only have been two. So to fix that, you’d enter this command:
When you press Return, Terminal will re-execute the prior command, making the correction you indicated. And to let you know what happened, Terminal will also echo the corrected command that was executed:
cp /etc/httpd/httpd.conf ~/Desktop/httpd_copy.conf
You may not use this every day, but it’s a nice timesaver for those times when you do make a mistake.