How many clipboards are in system?

7,089

Solution 1

The xclip manpages (man xclip) say this:

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

So you can specify the location:

echo !! | xclip -selection <selection>

Where <selection> is one of primary, secondary, clipboard.

Description of these from the ArchWiki: Clipboard

Of the three selections, users should only be concerned with PRIMARY and CLIPBOARD. SECONDARY is only used inconsistently and was intended as an alternate to PRIMARY. Different applications may treat PRIMARY and CLIPBOARD differently; however, there is a degree of consensus that CLIPBOARD should be used for Windows-style clipboard operations, while PRIMARY should exist as a "quick" option, where text can be selected using the mouse or keyboard, then pasted using the middle mouse button (or some emulation of it). This can cause confusion and, in some cases, inconsistent or undesirable results from rogue applications.

That means it depends on your environment. It may have inconsistencies, if the applications use different selections. Though if you use a desktop enivornment like Gnome it should work fine.

Also as mentioned by Kartik, you can copy-paste in most terminals with Ctrl+Shift+C/V.

Most applications in linux also support selection of text with the mouse to store something in the clipboard.

To get the content of from the clipboard use the -o flag:

xclip -o

If you use it often you can create aliases for those commands in you .bashrc:

alias cbcopy='xclip -selection clipboard'
alias cbpaste='xclip -selection clipboard -o'

Solution 2

For the record, in Cygwin you can direct your output to /dev/clipboard like so:

echo !! > /dev/clipboard

This copies the output to the system standard clipboard and you can use Ctrl+V or whatever to paste it.

Solution 3

To copy anything in linux from the terminal, there are two ways:

  1. Select it with the mouse to copy and paste it with middle click.
  2. Select with mouse and copy it with the keyboard shortcut. (which is different on different terminals, Ctrl-Shift-C/V on Ubuntu)

Sometimes you can copy and paste anything with Ctrl+C/V like windows (but not on the terminals).

EDIT: echo !! | xclip copies only the previous command.

Share:
7,089

Related videos on Youtube

Loom
Author by

Loom

Updated on September 18, 2022

Comments

  • Loom
    Loom over 1 year

    I was recently thrown there from the windows world and I'd like to ask some questions about clipboards in Linux (and Unix?) systems. What is X clipboard? How many clipboards are in Linux? Actually, I'd like to copy command from terminal to clipboard and then paste it in an other application (gedit, skype etc.). I entered echo !! | xclip in terminal. However when I tried to paste the command to other applications (via Shift+Ins or Ctrl+V), actually an old content have been pasted. At the same time I can paste this command in terminal.

  • Loom
    Loom almost 11 years
    Thank you. So, there in no way to copy in Linux from terminal without mouse?
  • Kartik
    Kartik almost 11 years
    @Loom I think you can copy with echo "something" | xcopy and paste with Shift + Ins
  • Loom
    Loom almost 11 years
    Thanks. What xcopy is and where I can find it?
  • Kartik
    Kartik almost 11 years
    @Loom Maybe outside terminal you can paste with Ctrl+V
  • Kartik
    Kartik almost 11 years
    @Loom I'm sorry i meant to say xclip
  • Loom
    Loom almost 11 years
    Unfortunately Ctrl+V doesn't working too
  • Kartik
    Kartik almost 11 years
    @Loom Please tell which Linux are you using?
  • Loom
    Loom almost 11 years
    I'm using Ubuntu
  • ahilsend
    ahilsend almost 11 years
    But that's only for Cygwin, isn't it?
  • user3834306
    user3834306 almost 11 years
    Oh, how embarassing! I didn't know that. Yeah, I have to use Cygwin, unfortunately. I'll update the answer. Thanks for the info