25

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

slhck
  • 223,558
  • 70
  • 607
  • 592
t3hcakeman
  • 351
  • 1
  • 3
  • 3
  • 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 Mar 28 '12 at 16:24

1 Answers1

33

Use pbcopy:

echo foo | pbcopy

Also see man pbcopy for info on it and pbpaste.

roguesys
  • 2,930
  • 19
  • 15