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 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 '14 at 9:33
possible cross site duplicate of: superuser.com/questions/301851/… – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Aug 13 '14 at 9:34
More general question for any file type: superuser.com/questions/796376/… – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Aug 13 '14 at 11:50

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

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

I've edited @don_crissti's answer to allow pipe input:

#!/usr/bin/env python

import sys
from gi.repository import Gtk, Gdk, GdkPixbuf

def store(pixbuf):
        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

def copy_image(f):
    image = Gtk.Image.new_from_file(f)
    if image.get_storage_type() == Gtk.ImageType.PIXBUF:
        pixbuf = image.get_pixbuf()
        print("Copying failed")

def copy_pixbuf(data):
    loader = GdkPixbuf.PixbufLoader()
    pixbuf = loader.get_pixbuf()

if sys.stdin.isatty():
    if len(sys.argv) != 2:
        print("Usage: image-to-clipboard.py image")
        f = sys.argv[1]
    data = sys.stdin.read()
share|improve this answer

A slightly modified version of the script in Mika Fischer's post, 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

Here's a short bash script that uses xclip to copy a file. Should be able to paste with ctrl-v.

command -v xclip >/dev/null 2>&1 || { echo "Need command xclip. Aborting." >&2; exit 1; }
[[ -f "$1" ]] || { echo "Error: Not a file." >&2; exit 1; }
TYPE=$(file -b --mime-type "$1")
xclip -selection clipboard -t "$TYPE" < "$1"

Thanks to...

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.