Copy text to the clipboard from the OS/X terminal

xvtk picture xvtk · Aug 5, 2012 · Viewed 9.6k times · Source

I am often having to copy and paste text from the terminal. Is there a way to redirect the output of a command into a shell variable or another command that would place the output in the clipboard?

Answer

Qsario picture Qsario · Aug 5, 2012

Use pbcopy and pbpaste. Anything sent to pbcopy goes into the clipboard. Running pbpaste sends the contents of the clipboard to standard output and you can chain them just like all other commands.

You can find some example uses here: http://osxdaily.com/2007/03/05/manipulating-the-clipboard-from-the-command-line/