2

When opening nautilus, choose a file and click ctrl+c copy the file into clipboard so that I can paste it in somewhere else in nautilus. And if the file is an image, I can even paste it in libreoffice. I want to know whether I can achieve the same effect as ctrl+c in command line without opening nautilus?

Simon
  • 419

1 Answers1

1

-target is a way for you to describe the content of the selection. In that sense, it's possible to label the selection incorrectly. It has more to do with how the receiving program handles atoms. LibreOffice in your example handles MIME targets.

$ file --mime example.png 
example.png: image/png; charset=binary

$ xclip -selection clipboard -t image/png -i example.png

You can list targets of the current selection with the special atom name TARGETS

$ xclip -selection clipboard -t TARGETS -o  
TARGETS  
image/png

Next example is Nautilus, the selection target is text/plain and a copy/paste has the format:

x-special/nautilus-clipboard
copy
file:///path/to/file.txt

Gives the xclip selection:

xclip -sel clip -t text/plain <(printf %s\\n x-special/nautilus-clipboard copy file:///path/to/file.txt)
  • Yes, this is a reasonable answer. And it works with many software such as libreoffice. But it does not work with nautilus, that is, I cannot paste it in nautilus with ctrl+v. However, if I press ctrl+c after selecting a file in nautilus, the paste function is available for both nautilus and libreoffice. It seems that nautilus uses another different target, something like x-special/nautilus-clipboard. But I cannot figure it out clearly, because specifying the target with x-special/nautilus-clipboard also does not work. – Simon Dec 06 '20 at 07:07
  • have you tried using a uri "file:///path/to/file.ext" with that target –  Dec 06 '20 at 07:12
  • I have tried echo "file:///path/to/file.png"| xclip -i -sel clipboard -target text/uri but it does not work.@bac0n – Simon Dec 06 '20 at 07:17
  • -t text/uri-list ? –  Dec 06 '20 at 07:28
  • Yes, the post above is my typo. Sorry for that. – Simon Dec 06 '20 at 07:37