3

Where in the file system is the file containing the content of the clipboard? If there is no file, then how is the clipboard maintained?

4
  • Which version of Unix or which Linux distribution. Which window manager? You're going to need to provide a lot more information unless this is a general question about clipboards. What's your specific problem? Jan 15 '16 at 18:45
  • Now I've seen your second question (unix.stackexchange.com/questions/255591/…), I suspect you're just asking the same thing in a different way. I suggest you close this one and concentrate on the other question. Jan 15 '16 at 18:46
  • How do I close this one?
    – Rohan
    Jan 15 '16 at 20:50
  • Similar question: askubuntu.com/q/729360/1073967 Nov 25 '20 at 11:12
7

The clipboard is not stored in the filesystem or even in a particular location in memory. In fact, there is no such thing as "the" clipboard; copy/paste is implemented via a communications protocol between applications.

When you copy text in an application (whether by selecting text, for the primary selection, or by an explicit 'copy' operation for clipboard selection), the application where you copy alerts the X server that it now owns that particular selection. When you paste, the application you paste into sends a request to the X server, which is redirected to the application that owns the selection. The data is only ever stored in the source application, and when you paste text, it's communicated from the source to the destination application in real time.

Tools such as xsel, which act as if they're just moving data into a persistent storage space, are faking it; they fork to background to create an X application with no windows, which holds the data to select until it lapses, then exits.

4
  • 1
    So by what you are saying, if I close the application I want to copy from, I lose that content?
    – Rohan
    Jan 15 '16 at 20:52
  • Yes. xsel gets around this by hiding in the background, and if you run a clipboard manager it'll save it as well, but that's the general rule.
    – Tom Hunt
    Jan 15 '16 at 20:57
  • But that has not been the case for me.
    – Rohan
    Jan 16 '16 at 5:25
  • I killed my graphical session and started another one, and the clipboard did not lose it's content. I am not sure that X died, however it might have, maybe it is saved in on of the gvfs* processes (or dbus?). I went to maintenance target and then back to default. The clipboard was gone. So yes, although you'd expect linux to do something like save it in a file - which would also make it accessible from VTs - it sadly does not.
    – Rolf
    Mar 4 '18 at 18:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.