Manipulating the clipboard in the Terminal: pbcopy and pbpaste
Mac OS X provides two utilities that make it possible to manipulate the clipboard in the Terminal: pbcopy and pbpaste.
pbcopy puts the data it receives via standard input into the clipboard.
echo "Hello, World!" | pbcopy
pbcopy < aFile
pbpaste does the opposite. It ouputs the clipboard to the standard output.
pbpaste
pbpaste > anotherFile
It is possible to select the preferred format for the clipboard data using the -Prefer option:
-Prefer rtf|ps|ascii
Both commands also accept the -help option:
Usage: pbcopy [-help]
Usage: pbpaste [-help] [-Prefer rtf|ps|ascii]