There are two command-line tools (in two different packages) to access the X clipboard:
xclip
xsel
I would love to know the difference between those two and hear a recommendation which one to use in which cases.
There are two command-line tools (in two different packages) to access the X clipboard:
xclip
xsel
I would love to know the difference between those two and hear a recommendation which one to use in which cases.
Both
xclip
andxsel
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 thatxclip
wins in one aspect - reading from an input file:Of course you could use shell redirection with
xsel
to get around thatxclip
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 stdoutIn 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:
Something else to keep in mind,
xsel
has fewer dependencies thanxclip
:Use
xclip
, becausexsel
can not extract binary data from clipboard, such as screenshots. For example, save screenshot to clipboard:Then save to file and compare output:
There is one other reason to use xclip over xsel – xclip can manipulate cut buffer 0, by passing
-selection buffer-cut
, which xsel cannot do.It's relatively easy to allow it to manipulate the other cut buffers as well; here is my patch, though it's not well-tested and comes with no guarantees.
For me
xclip
will let zsh shellexit
very slowly when usingguake
.Like run command:
$ pwd | xclip -selection c
. Then run$ exit
to quit shell.$ exit
need seconds to quit.xsel
is good with this situation.xclip
has this special feature to remove last empty line of copied selection wherexsel
don't have this option.-rmlastnl remove the last newline charater if present