The Clipboard and the Command Line

Two of the most useful features on Mac OS X are the clipboard and the command line.

I am forever copying and pasting between applications using the clipboard. Select text in one application, press ⌘C, switch to the other application and then press ⌘V and the selected item appears in the application.

The beauty of the Unix command line is worthy of whole blog by itself. Utilities such as grep, find, sort, uniq, less, tail, head, cut are great.

Imagine being able to use these with the clipboard. You can! That is what the commands pbcopy and pbpaste do

Want to include disk space usage in an email? Open a terminal window and enter the df -H | pbcopy, switch to the email and press ⌘V to paste it in.

Want to take a list of names in an email and sort them? Select the lines, press ⌘C to copy to the clipboard, switch to the terminal window and enter pbpaste | sort | pbcopy. Then switch back to the email and pres ⌘V to paste in the sorted lines from the clipboard into the document.

Windows users need not fear. Install Cygwin and the putclip and getclip commands, part of utilities, and you can achieve the same effect.