Is there a command to output the current value of the clipboard?

Example (this command doesn't exists, it's just an example of what I'm looking for:

cat clipboard
> Hello world!

Also, if the clipboard is stored somewhere, where is it located?

  • Duplicate question. See unix.stackexchange.com/questions/3892/… Feb 6 '14 at 3:13
  • 1
    @QuoraFea I don't think this is a duplicate, the link you provided is about inserting a value to the clipboard. What I was looking for is to display the value of the clipboard. By looking at question that you've linked, I wouldn't have found my answer.
    – Timber
    Feb 6 '14 at 3:16
  • Then see this one: stackoverflow.com/questions/749544/pipe-to-from-clipboard It is both ways. Feb 6 '14 at 3:19
  • 1
    @QuoraFea Questions are only "duplicate" if they are from the same site on the Stack Exchange network.
    – Chris Down
    Feb 6 '14 at 3:41
  • @ChrisDown: thanks for the clarification. In this case, only the second covers completely this question. The first is actually the inverse case, how to get the value of the clipboard (although we can deduce from there, how to copy into the clipboard) Feb 6 '14 at 16:39

You can use xclip or xsel to do this.

xclip -o
xsel -o

Bear in mind that there are multiple X clipboards (well, "selections", including the major two, PRIMARY (typically used when you select text) and CLIPBOARD (typically used when you explicitly request a copy)). You may need to select which clipboard you are referring to:

xclip -o -selection primary
xsel -op

xclip -o -selection clipboard
xsel -ob

# XA_SECONDARY (you probably don't want this)
xclip -o -selection secondary
xsel -os

For the macOS clipboard, use pbcopy.

  • Hmm, it looks like xsel and xclip is an external program, is there a native command to do this? Is the clipboard value stored in a file some where? <- I'll add this to the question.
    – Timber
    Feb 6 '14 at 2:54
  • 1
    @TimothyOnggowasito - no it's not in a file. It's in memory.
    – slm
    Feb 6 '14 at 2:55
  • 2
    @TimothyOnggowasito There is no "native" way because the concept of these selections is entirely specific to your X server. The contents is stored in-memory, not in a file, and as far as I know it is not exposed as one anywhere.
    – Chris Down
    Feb 6 '14 at 2:55
  • @ChrisDown Thanks! I didn't know that. I've downloaded and installed both programs. It works just as I expected. Thank you so much :). Though I wished that they put a line break after the output... Hello World!timothy@timothy-VirtualBox:~$
    – Timber
    Feb 6 '14 at 3:03
  • 3
    @TimothyOnggowasito In many situations it would be annoying if it automatically added a newline -- you wouldn't be able to tell between content which really did have a newline at the end when copied, and that which didn't.
    – Chris Down
    Feb 6 '14 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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