Copy and Paste File Contents to and from Clipboard from CLI on MacOS

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives the steps to copy contents of a file to clipboard from CLI on Mac. Hella cool command I wish I knew years ago!

Ubuntu has a command named xclip that is similar.


Copy Contents from File to Clipboard

pbcopy < ~/.ssh/id_rsa.pub


Paste Contents from Clipboard to File

pbpaste > ~/pastedcontent.txt


Filter Pasted Contents from Clipboard to File

pbpaste | grep blah > ~/pastedcontent.txt


Sources