Published on

Copy and Paste Contents from the CLI with pbcopy and pbpaste


If you want to automate things in shell, especially copy-paste things from the terminal then pbcopy and pbpaste commands might be a good choice for you on MacOS.

With those commands, we can copy paste contents from and to the clipboard easily.


pbcopyCopies the output from the previous command to the clipboard
pbpasteOutputs the contents of the clipboard to the standard output (stdout)
echo "Copy this" | pbcopy # Now your clipboard will have "Copy this"
echo $(pbpaste) # "Copy this" is printed on the terminal

Happy copy-pasting texts!