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.


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
  • 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
  • 1
    If your distro provides xsel, an alternative to xclip, you can use echo 'Hello World' | xsel -i -p && xsel -o -p | xsel -i -b. It's slightly different and less efficient than xclip due to xsel lacking a filter option. But if you're stuck with xsel then this is a way to solve the problem. – starfry Feb 5 '17 at 11:55

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.

  • 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
  • I have tested here on my zsh and it works like a charm! – SergioAraujo Aug 22 '19 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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