pbcopy / pbpaste in Ubuntu (command line clipboard)

words by Brian Racer

OS X has a neat command-line tool called pbcopy which takes the standard input and places it in the clipboard to paste into other applications.

In Ubuntu(or any Linux distro with Xwindows), a similar tool is xclip. I like to make this alias:

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

or the following also works if you would rather use xsel:

alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'

Now you can pipe any text to pbcopy

$ cat ~/.ssh/id_dsa.pub | pbcopy

Your public ssh key is transferred to your clipboard and is ready to be pasted(perhaps with pbpaste).

2 Responses to “pbcopy / pbpaste in Ubuntu (command line clipboard)”

  1. Caffeine Driven Development » Blog Archive » L33t Links #16 says:

    [...] Jetpack Flight Log ยป pbcopy in Ubuntu (command line clipboard) [...]

  2. Peter Lewis says:

    Thanks. I know I used something a little more gnome-ish in the past, but just couldn’t remember it.

    BTW…. you may need to install xsel or xclip.

    $ sudo apt-get install xsel

Leave a Reply