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


echo sometext | copy_to_clipboard


echo sometext > /private/clipboard.txt


1 Answer 1


Use pbcopy:

echo foo | pbcopy

Also see man pbcopy for info on it and pbpaste.

  • 1
    Or for a file, e.g. rsa key use pbcopy < ~/.ssh/id_rsa.pub Dec 1, 2018 at 16:16
  • But what if you SSH into some say Linux box and pbcopy is a local utility on the Mac? Jun 3, 2022 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.