21

We have a Linux server, and there are multiple users (thus multiple accounts) on that server. So logically, there would be different clipboards for different users.

My question is: just like in Windows we can have a clipboard viewer, how can I see the contents of clipboard on Unix?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
maggi
  • 211

4 Answers4

21

Your reasoning is sound, but you started from an incorrect premise. Linux does not really have "clipboards", that concept just isn't part of the operating system. Instead, the windowing system, almost always X11, implements clipboards. The X11 server, which manages and runs the display, does clipboards. That way, a clipboard is a property of a user-level program, not the operating system, and moreover, there's one set of clipboards for each display (which is more-or-less each monitor or screen, but not always).

That said, the X11 clipboard is a bit weird.

As far as seeing the contents, I've always been fond of xcb, but that's apparently considered pretty obscure these days. You might like parcellite, but look around, it appears that many X11 clipboard managers and interaction programs exist.

  • 1
    Not just window systems - there's also gpm daemon which implements selections for consoles. I'm not sure how/whether you can read and write gpm's selection. – Toby Speight Feb 06 '21 at 14:51
14

A clipboard is nothing special and just a implementation detail for some programs, e.g. X, Emacs, Vim, and other programs have implementations what you could refer to as "clipboards".

As you are talking about a server I assume your users log in into the system via ssh. That means there isn't any clipboard for these users. This is handled by their host system and terminal.

If you want to access the X clipboard there are multiple solutions, for example:

  • xclip - a command line interface for the clipboard
  • clipit - a clipboard manager without dependencies to other desktop environments

If you want to access the X clipboard content for another user, you have to access the X session for this user.

There are many other things you can look into, e.g. autocutsel, integration between X clipboard and Emacs, etc.

Ulrich Dangel
  • 25,369
2

In emacs, examine

clipboard-kill-region
clipboard-kill-ring-save
clipboard-yank

I wrote this to copy a whole buffer to the clipboard:

(defun copy-all ()
  "copy buffer to clipboard"
  (interactive)
  (clipboard-kill-ring-save (point-min) (point-max))
  (message "Copy done.") )

Also, I've made a useful alias called xc, like this: xclip -selection clipboard. Then, echo $(pwd) | xc (for example) will send your directory tree position to the clipboard.

And, by accident, I noticed I can paste into urxvt by pushing the mousewheel button. I don't like using the mouse at all, so if you know how to bind this to a keyboard shortcut, please tell me.

Edit: I found (somewhere on this site) that the answer to the final (my) question is - it is already done, namely Shift-Insert.

Emanuel Berg
  • 6,903
  • 8
  • 44
  • 65
  • You should post your bind-paste-to-keyboard-shortcut as a question - you'll get better help that way. –  Jul 29 '12 at 14:04
  • @BruceEdiger: Right, but everything else in the post including how to paste into a terminal (at least one way to do it) is useful as I understood the question so - you see where I'm getting? - just ignore the last sentence if it bugs you :) – Emanuel Berg Jul 30 '12 at 16:26
0

If you are in a Gnome environment, try GPaste. The feature I wanted - and this clipboard manager has - is that it presents the copied image DIMENSIONS in pixels.