'xclip' vs. 'xsel'
Solution 1:
Both xclip
and xsel
can store text into 3 different selections (by default it is primary selection). From experience I know that primary selection is basically what you high-light and released with the middle mouse click (which corresponds to pressing both right and left touchpad key on a laptop). The clipboard is the traditional CtrlV.
By examining the man
pages for both, however, I've discovered that xclip
wins in one aspect - reading from an input file:
$ cat testfile.txt
HELLOWORLD
$ xclip -selection clipboard testfile.txt
$ HELLOWORLD
mksh: HELLOWORLD: not found
$ xsel testfile.txt
Usage: xsel [options]
Manipulate the X sele . . . (usage page goes on)
Of course you could use shell redirection with xsel
to get around that
$ xsel --clipboard < testfile.txt
$ HELLOWORLD
mksh: HELLOWORLD: not found
xclip
also wins in the fact that you can output the contents of clipboard to file (which is perhaps useful when you want to redirect PRIMARY selection , i.e. highlights). xsel
offers only output to stdout
Solution 2:
In addition to @Serg answer, there is a piece of information from the Tmux page in the Arch Wiki that can be useful in some specific cases:
Unlike xsel [xclip] works better when printing a raw bitstream that does not fit the current locale. Nevertheless, it is neater to use xsel because xclip does not close
STDOUT
after it has read from the tmux buffer. As such, tmux does not know that the copy task has completed, and continues to wait for xclip to terminate, thereby rendering tmux unresponsive. A workaround is to redirectSTDOUT
to/dev/null
: