8

I'd like to copy and paste to the clipboard from the command line.

I've found two utilities that works with "mouse" selection: xclip and xsel. But they both ignore the clipboard that is filled with Ctrlc in GUI applications. So I may not paste things that were copied in this way.

What command line utility works like xclip or xsel but is compatible with Ctrlc and Ctrlv?

1
  • It looks like xclip and xsel accept an option -selection clipboard to use a non-default X selection. Did you try that? Commented Mar 9, 2015 at 6:49

1 Answer 1

15

xclip uses the clipboard if you specify -selection clipboard:

xclip -selection clipboard -o 

prints the contents of the clipboard (as filled with Ctrl-C in a GUI application).

The equivalent option for xsel is -b (or --clipboard).

4
  • xclip works perfectly. But I'm confused. I've already tried -selection clipboard and get no result. There are conditions under which it doesn't work, but I'm failed to reproduce this conditions Commented Mar 9, 2015 at 6:53
  • 3
    The X selection/clipboard has a few weird edge cases; see jwz.org/doc/x-cut-and-paste.html for an overview (and tronche.com/gui/x/icccm if you want all the details). Commented Mar 9, 2015 at 6:57
  • 1
    You can use -se c instead of the long -selection clipboard, too. Commented Mar 9, 2015 at 12:12
  • Some times xclip not works: when i copy text in firefox, then switch to linux console, and run DISPLAY=:0 xclip -selection clipboard -o, it block forever. This problem will gone after i restart firefox. Commented May 10, 2019 at 2:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.