PBCopy Mac command

A couple of useful Mac terminal (or iTerm) commands are the PBCopy & PBPaste. Here is a demonstration of how they work.

There are two basic ways to copy using pbcopy:

$ pbcopy < source_file.txt
copies text in source_file.txt

$ pwd | pbcopy
copies the output from pwd (the current directory) to the Mac clipboard

The copied text can now be pasted (either using menu’s or the CMD + V keyboard shortcut) into other applications in the usual way.

PBPaste works using the same syntax but in reverse:

$ pbpaste > destination_file.txt
pastes the current Mac clipboard to destination_file.txt

$ cd `pbpaste`
change directory to what's is currently stored in Mac clipboard

Leave a Reply