Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a terminal in OSX I can pipe output to pbcopy and then go into a web browser and paste it. I tried this in Linux with xcopy but when I switch to the browser it just overwrites the clipboard with with whatever was in it the last time the browser was used. What works like pbcopy in Linux?

share|improve this question
...and for those that don't know what pbcopy is, here's the man page… – Rob Cowell May 25 '11 at 9:48
+1 for my new favorite tool! – Chris Nava May 25 '11 at 14:09
up vote 82 down vote accepted

if you have X installed you may try xsel in this way :

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

or with xclip :

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

now you can use'em :

echo 'go to my clipboard' | pbcopy

when I don't have X I use GNU Screen functionality to copy between open shells in a session using keyboard

to copy : Ctrl-a -> Esc -> go to wanted position * -> Space (to begin selecting) -> press k to go forward mark text -> Enter

to paste : Ctrl-a + ]

* movements are done with vim like key bindings (j, k, l & m).

share|improve this answer
Thanks this is exactly the information I wanted. Tho now I wonder if there is a way I could make Screen let me use Emacs commands to select the area I want to copy... – Noah Sussman Dec 31 '11 at 16:58
xsel: Can't open display: (null) : Inappropriate ioctl for device – itsazzad Dec 24 '15 at 10:16

Put a script like this called pbcopy in your bin folder:

xclip -i -sel c -f |xclip -i -sel p

This will put STDIN in both your selection buffer and clipboard:

echo Hello world |pbcopy
share|improve this answer
Why would the cat be needed? Won't it just redirect stdin to stdout in this case thus useless cat abuse or am I missing something? – Hultner May 21 '15 at 7:53
You're right it does seem like useless cat abuse :-) – Erik May 25 '15 at 10:44

To expand on the solutions of @Erik and @xpixelz; these two scripts should work on both platforms:


__IS_MAC=${__IS_MAC:-$(test $(uname -s) == "Darwin" && echo 'true')}
if [ -n "${__IS_MAC}" ]; then
  cat | /usr/bin/pbcopy
  # copy to selection buffer AND clipboard
  cat | xclip -i -sel c -f | xclip -i -sel p


__IS_MAC=${__IS_MAC:-$(test $(uname -s) == "Darwin" && echo 'true')}
if [ -n "${__IS_MAC}" ]; then
  xclip -selection clipboard -o
share|improve this answer
But why would you even have this script on OS X where it's a part of the native userland? – Hultner May 21 '15 at 8:02
* as a reference for similar functionality, * cross-platform dotfiles: – Wes Turner May 27 '15 at 17:41
Still cat abuse and why not check if xclip exist instead and assign an alias if it does? Or check if the pbpaste binary exist would also be an option. Checking the uname seems like an odd approach to the problem. – Hultner May 29 '15 at 15:19
@Hultner "Checking the uname seems like an odd approach to the problem" You could also check for binaries, preferentially, in order, by exception with a ${a:-${b:-${c:+${d}}}} and some type -P/ has variable assignments and /bin/test execs. – Wes Turner Dec 13 '15 at 20:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.