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 way in a bash to copy a picture to the clipboard?

For example if there is a picture mypic.png I want to have a command like clipcopy mypic.png such that I can go for example to inkscape and paste it afterwards.

share|improve this question
This should be broken in two steps: 1. what data does Inkscape expect to be on the clipboard? E.g. file content or file path. I imagine content since path is trivial with xsel -b? 2. How to get that data on the clipboard. –  Ciro Santilli Aug 13 at 9:33
possible cross site duplicate of: superuser.com/questions/301851/… –  Ciro Santilli Aug 13 at 9:34
More general question for any file type: superuser.com/questions/796376/… –  Ciro Santilli Aug 13 at 11:50

3 Answers 3

This python script by cheshirekow claims to do what you want.

#! /usr/bin/python
import pygtk
import gtk
import os
import sys

def copy_image(f):
    assert os.path.exists(f), "file does not exist"
    image = gtk.gdk.pixbuf_new_from_file(f)

    clipboard = gtk.clipboard_get()

share|improve this answer
Thanks, it works to past into libreoffice, however pasting into inkscape doesn't. –  student Jan 27 '12 at 14:58

A slightly modified version of the above, using python+gtk3:

#!/usr/bin/env python

import sys
from gi.repository import Gtk, Gdk

def copy_image(f):
    image = Gtk.Image.new_from_file(f)
    clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    if image.get_storage_type() == Gtk.ImageType.PIXBUF:
        print("No image has been pasted yet.")


Pasting into gimp, inkscape, libreoffice works OK here.

share|improve this answer

You can use CopyQ for this. From the website:

Clipboard manager with advanced features

  • CopyQ is clipboard manager with searchable and editable history.
  • Supports Linux and Windows.
  • Experimental support for OS X 10.9+.
  • Store text, HTML, images and any other custom format.
  • Advanced command-line interface and scripting.

To copy an image (you need to indicate the MIME type):

copyq write image/png - < file.png && copyq select 0

To copy a data file (you need to indicate the MIME type):

copyq write application/pdf - < file.pdf && copyq select 0

Check their wiki for more documentation and usage examples.

See also:

share|improve this answer

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.