Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to take an image from the clipboard and output it to a file (using X)?

I can do this with text easily:

$ xclip -selection c -o > file.text

But when I try the above with an image nothing is written.

The reason I want to do this is I don't have an image editor installed, and it got me thinking whether I could do this without installing one.

share|improve this question
up vote 17 down vote accepted

You can actually do this with xclip. The secret is the -t option, which refers you to the ICCCM Section 2.6.2. Which I confess I don't blame you for failing to read... Anyway, an example, I have just right-clicked your avatar in Chromium and selected "Copy Image":

  1. See what targets are available:

    $ xclip -selection clipboard -t TARGETS -o
  2. Note the image/png target; go ahead and get it:

    $ xclip -selection clipboard -t image/png -o > /tmp/avatar.png
    $ see /tmp/avatar.png    # yep, that's it

NOTE: Some research shows that you need xclip from SVN revision 81 (from April 2010) or later to have the required -t option. Or apply the patches yourself.

share|improve this answer
This isn't working for me. When I look at the man page for xclip there isn't a -t option? – Lerp Jul 18 '14 at 9:46
@Lerp I have xclip 0.12+svn84-4 (Debian) here... which version are you on? – derobert Jul 18 '14 at 16:36
@Lerp I looked through the SVN repository history, and found where that option was added. Answer updated. – derobert Jul 18 '14 at 16:44
I am using 0.12, the one that is offered by pacman so I shall have to get the upstream version. Thanks! – Lerp Jul 21 '14 at 8:23

Your Answer


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.