When I made the switch to Mac from Windows one of the things that I enjoyed the most was having access to a full featured console window. The Terminal in OSX is much more powerful than the Command shell in Windows out of the box. Not only do I have quick access to all of the great Unix commands for things like file viewing and management, I can quickly SSH into my remote Linux based servers very easily.
Most people are aware of the standard things you can do in a Terminal shell, much like you can do in a Windows Command prompt: hit the up arrow to cycle through previous commands and hit the Tab key to help complete the name of a directory/folder. There are a couple of other things that I’ve found that really help out:
Search Command History (Control-R)
Rather than hitting the Up Arrow 10 times to get to an older and lengthy command you can simply hit Control-R. This will give you a prompt that allows you to start typing in a command and the first match it finds from your command history will be displayed as you type. Since I found this I use it constantly and rarely hit the Up Arrow to repeat a previous command.
Cursor Navigation (Escape-F, Escape-B)
I’m a heavy keyboard user yet when I jump into the Terminal I feel like my fingers are tied sometimes. This is especially true when trying to navigate between words in a long command line; I hit Command-Right or Command-Left and switch tabs in my command windows. Instead of using Control modified keys the Escape key comes into play here. Hitting Escape, then hitting F (forward) or B (back) jumps the cursor from word to word in the command line. It’s less efficient than hitting a Control or Command modified key but it beats standing on the Left and Right arrows.
Delete to End of Line (Control-K)
Very often I find myself executing the same command on a different target. This usually involves deleting the last portion of a previously run command. Before picking up some of these shortcuts I would simply up arrow to the previous command and then stand on the Delete key until I got to the point I wanted. Now, I use the Escape-B command to back up to the right point in the previous command and then hit Control-K to delete from that point to the end of the line.
So there are the three shortcut combinations I’ve found invaluable in the Terminal window, and the best part is they are pretty universal to the Bash shell so when I’m in my SSH’d into one of my Linux servers I can use them there as well.
Got a shortcut you use in Terminal that you use all the time? Drop a note in the Comments below.