Last Updated: February 25, 2016
· ryepdx

pbcopy and pbpaste under *nix

If you're a recent transplant from OS X, or if you just do a lot of copying and pasting from the command line under X and want to save yourself some typing, you might find it helpful to add these aliases to your .bashrc:

alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'

This allows you to copy files or command output to the clipboard, and paste your clipboard to files and the command line.

For example, to decrypt my Bitcoin WoT authentication challenge string and copy it to my clipboard, I can just run:

wget -O - | gpg -d | pbcopy

The line above just grabs the text at, passes it to gpg for decryption, and then passes the decrypted string to my clipboard via the pbcopy alias.

Alternatively, if I want to copy a file:


This does rely on xclip, which may not already be on your system. To install it under Ubuntu:

sudo apt-get install xclip

The source code for xclip can be found on Sourceforge.