Terminal tricks for OS X users
If you regularly use Terminal, here are some tips and tricks to greatly increase your productivity.
Terminal is a very powerful tool which can be used for anything from development to running scripts, to finely manipulating the OS X configuration and customizing the system for your needs. For anyone familiar with a standard BSD terminal interface, the OS X Terminal will be very familiar; however, there are a number of small tricks available when using Terminal in OS X, which can greatly enhance your uses of the Terminal.
The two more useful tricks are how you can manage file and folder paths in the Terminal. Often you might be at a specific path in the Terminal and wish to reveal it or a targeted file in the Finder, which can be done using the "open" command in the following ways:
- Open the current Terminal folder in the Finder
- Reveal a specified file in the Finder
open -R path/to/file
In addition to revealing or opening items from Terminal in the OS X Finder, you can specify a full path to items in the Finder by dragging and dropping them in the window. For instance, if you would like to change directories to a directory within a shared folder you have mounted on your Desktop, then you can do so by typing "cd" followed by a space, and then locate the desired directory in the Finder and drag it to the Terminal window. This will input the folder path, with all appropriate escaped characters, and you can then press Enter to execute the command and switch directories.
The next tip involves the OS X clipboard, where you might have some complex output from various commands which you might like to place in another document. You can always redirect output to a text file or two, but OS X also supports the "pbcopy" command, to which you can pipe contents so they will be placed on the clipboard. For instance, you can run the following command to echo some text and have it placed on the clipboard:
echo "hello world" | pbcopy
With contents on the clipboard in this manner, you can retrieve them using the "pbpaste" command, or you can go to any application that supports copy and paste functions and paste the contents there.
Another feature of Terminal is the ability to position your cursor. If you have dealt with command line tools before, you might find one of the biggest frustrations is going back and editing a mid-section of an entered command before executing it. If you do this, or if you use any terminal-based editors like "nano," then you might find yourself pressing and holding arrow keys to move your cursor to the desired location. However, OS X supports a quick option to place your cursor with a click of the mouse. Simply hold the Option key, and the mouse will turn into a crosshair. Now you can click on a location otherwise navigable by arrow keys, and OS X will place your cursor at this point.
Finally, Terminal offers a few options for looking up command information you might encounter. While you can use the "man" command to look up the manual page for a specific command for function, doing this will take over your current Terminal window. Instead, you can right-click a specific command and choose from among options to open the man page in a separate window, search the man page index, or even perform a Google search for the selected term.
With these options, your productivity in Terminal can greatly increase, and can make navigating your system and switching between Terminal use and Finder use far more seamless.