pbcopy and pbpaste for Linux

Tags: , , , , , , — Jeff @ 14:43

Mac OS X has the useful commands pbcopy and pbpaste. pbcopy reads the contents of standard input into the clipboard; pbpaste writes the contents of the clipboard to standard output. These commands aren’t part of the standard set of commands on Linux, but they’re easily added. Simply install the XSel program via a package management system or directly from source, then add these lines to ~/.bashrc. Voilà! Easy commandline access to the clipboard.

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


  1. And Vista’s pbcopy equivalent is `clip` (which, oddly, has awk in one of the documentation samples – even though they don’t ship with awk). I don’t know what the Windows equivalent of pbpaste is.

    Comment by Mook — 23.10.09 @ 21:04

  2. There’s also xclip. Equivalent commands are:
    alias pbcopy=’xclip -selection clipboard’
    alias pbpaste=’xclip -selection clipboard -o’

    Comment by Chris AtLee — 23.10.09 @ 21:05

  3. Are they really equivalent to Mac?

    On OSX pbcopy/pbpaste allow to copy in RTF format, XSel allows only plain text copy/paste.

    Table2Clipboard uses the RTF format to make happy iWorks

    [Perhaps not. I don’t particularly care about rich-text copying, tho — especially not for commandline integration! — so for my purposes (and, I would assume, the purposes of most commandline users) they’re equivalent.]

    Comment by dafi — 23.10.09 @ 23:41

  4. Cool find (both Linux and OS X), thanks for sharing.

    Comment by sime — 24.10.09 @ 01:02

  5. Funny, coming from Cygwin I aliased “getclip” and “putclip” on my Mac to “pbpaste” and “pbcopy”, respectively.

    Comment by Jan! — 26.10.09 @ 01:56

  6. You don’t actually need –input and –output; xsel will automatically figure out which one you want, based on whether you read from the output or write to the input.

    [Hum, that’s way magical — and wrong. 😉 Explicit is better than implicit. I will continue to use --input and --output even if they are mere talismans.]

    Comment by Anonymous — 26.10.09 @ 20:25

  7. Powershell also has clipboard manipulation commands, you’ll have to apropos its command list, though- because I’ve forgotten what they are.

    Comment by jafraldo — 08.12.09 @ 08:31

  8. You can use these to fix a buffer using:

    Comment by Tom Schneider — 23.04.11 @ 10:47

  9. very useful! Thanks!

    Comment by Alfred — 29.01.12 @ 15:07

  10. pbcopy & pbpaste are now available for windows https://ghuntley.com/archive/2016/01/20/pbcopy-pbpaste-for-windows-released/

    Comment by Geoffrey Huntley — 19.01.16 @ 13:43

RSS feed for comments on this post. TrackBack URI

Leave a comment

HTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>