Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
Duplicate question. See unix.stackexchange.com/questions/3892/… –  Quora Feans Feb 6 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. –  Timothy Onggowasito Feb 6 at 3:16
    
Then see this one: stackoverflow.com/questions/749544/pipe-to-from-clipboard It is both ways. –  Quora Feans Feb 6 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 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) –  Quora Feans Feb 6 at 16:39

1 Answer 1

up vote 5 down vote accepted

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:

# XA_PRIMARY
xclip -o -selection primary
xsel -op

# XA_CLIPBOARD
xclip -o -selection clipboard
xsel -ob

# XA_SECONDARY (you probably don't want this)
xclip -o -selection secondary
xsel -os
share|improve this answer
    
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. –  Timothy Onggowasito Feb 6 at 2:54
1  
@TimothyOnggowasito - no it's not in a file. It's in memory. –  slm Feb 6 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 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:~$ –  Timothy Onggowasito Feb 6 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 at 3:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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