Copy terminal output to Mac clipboard?

18

4

I need to directly copy the terminal stdout to the clipboard on Mac. How would I do this?

Example:

echo sometext | copy_to_clipboard

or

echo sometext > /private/clipboard.txt

t3hcakeman

Posted 2012-03-09T18:14:21.453

Reputation: 281

I am interested to know if it is possible to do this when ssh'ed to another box as well http://superuser.com/questions/405491/how-can-i-copy-the-output-from-a-remote-command-into-the-local-clipboard

– cwd – 2012-03-28T16:24:14.173

Answers

23

Use pbcopy:

echo foo | pbcopy

Also see man pbcopy for info on it and pbpaste.

roguesys

Posted 2012-03-09T18:14:21.453

Reputation: 2 640

Or for a file, e.g. rsa key use pbcopy < ~/.ssh/id_rsa.pub – Max MacLeod – 2018-12-01T16:16:02.300