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).

  • Pingback: Caffeine Driven Development » Blog Archive » L33t Links #16

  • Peter Lewis

    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

  • elmimmo

    It also copies the newline at the end. Anyway to delete it from before passing it to xsel/pbcopy?

  • elmimmo

    This seems to do it:

    alias pbcopy=’perl -pe “chomp if eof” | xsel –clipboard –input’

  • elmimmo

    Does not seem to work on remotes shells (SSL).

  • http://ananthakumaran.github.com/ Anantha Kumaran

    Thanks dude

  • http://profiles.google.com/sgheeren Seth Heeren

    nice. Thanks for sharing

  • Pingback: Sending data to the clipboard from command line « codissimo!

  • Sagar Mehta

    sweet – this is pretty cool!!

  • Pingback: Mac OSX – copy terminal output to clipboard « Developmentality

  • India Arham

    exact thing i was looking for

  • Anonymous

    Thanks, buddy! Was looking just for this…