Some quick terminal keystroke shortcuts
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.
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.
Comments
The reverse (go to the end of the line): Control-E
This will transfer the function of the "Esc" key to the "Option" key and save some finger stretching :-]
Now, if you hit Option-D, it will delete the word that your cursor sits on....
Some other emacs commands: ctrl-f and ctrl-b do the same as the left and right arrow keys. I tend to use that instead of the arrow keys because I don't need to remove my hands from the home key area.
ctrl-w deletes the previous word.
I just started a my O/S course in Computer Science and we're about to start Unix, hopefully with the help of this post, and the comments that follow, I'll be ahead of the curve.
Unix shells have a tendency to do that to people ;-). There are two lines you can go down for this: the first is any good tutorial (of which there are literally hundreds on the web) for BASH, the default shell for the Terminal. The second is to pick up a Mac specific book on the topic. Though it is targeted at Tiger most everything in A Practical Guide to Unix for Mac OS X Users contains a very thorough treatment on the topic.
Hope this helps!
It's good stuff. ^^
http://code.google.com/p/blacktree-visor/