How do I copy files (e.g. pictures) to clipboard using bash so that I can paste them into other programs?

If I view an image in Firefox and right click and copy the image, then I can directly paste it into other program like for example telegram using Ctrl+V to send the image. I would like to have that functionality that I could do that from bash too.

I tried using

cat image.png | xclip -selection c

when I then press Ctrl+V in telegram, it pastes


as text instead of pasting the image.

Using xclip-copyfile does not work either, it does not change the content of the clipboard that is used when pressing Ctrl+V in telegram at all.

  • Does copying the file's full path & name work "good enough"? – Xen2050 Jan 10 at 6:20
xclip -selection clipboard -t "$(file -b --mime-type "$img")" < "$img"
  • 1
    Although this may help to solve the problem, it doesn't explain why and/or how it addresses the issue. Providing this additional context would significantly improve its long-term educational value. Please edit your answer to add explanation, including the parameters and what limitations and assumptions apply. Thanks. – fixer1234 Jan 11 at 5:53

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.