Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

When copying text to the clipboard, xclip provides several selection targets:

    specify which X selection to use, options are:
    "primary" to use XA_PRIMARY (default), 
    "secondary" for XA_SECONDARY 
    "clipboard" for XA_CLIPBOARD

Is there a way to target multiple selections?

I have tried the following options

  1. echo "Hello world" | xclip -i -selection primary -selection clipboard
  2. echo "Hello world" | xclip -i selection primary | xclip -i selection clipboard
  3. echo "Hello world" | xclip -i selection primary,clipboard

but none of them worked.

share|improve this question
up vote 8 down vote accepted

I have tried the following options

echo "Hello world" | xclip -i selection primary | xclip -i selection clipboard  

You were really close there...
If you use -f with the first xclip command it will print the text back to stdout and you can pipe it to the second xclip command:

echo "Hello World" | xclip -i -sel p -f | xclip -i -sel c

From man xclip:

-f, -filter
            when xclip is invoked in the in mode with output level set to
            silent (the defaults), the filter option will cause xclip to print
            the text piped to standard in back to standard out unmodified
share|improve this answer
Thanks! I am accepting this solution because: 1) It informs about an interesting feature of xclip. 2) It allows me to pipe xclip commands which is quite convenient and 3) For some odd reason, it's the only answer so far that gives a working solution in my experiments for binding copy-pipe in tmux (this is what prompted this question) – Amelio Vazquez-Reina Mar 25 '13 at 20:18

I don't use xclip, so there may be a way to do this natively which I'm not aware of. In any case, this should work assuming your shell is bash:

echo "Hello world" | tee >(xclip -i -selection primary) >(xclip -i -selection clipboard) >/dev/null

>() is a form of process substitution. bash replaces each with the path to a file descriptor which is connected to the standard input of the program within the parentheses.

share|improve this answer
Thanks! Do you know if that syntax compatible with zsh too? – Amelio Vazquez-Reina Mar 25 '13 at 17:33
@user815423426 As far as I know, yes. – Chris Down Mar 25 '13 at 19:38

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.