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
?
Asked
Active
Viewed 904 times
2

Simon
- 419
1 Answers
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 withnautilus
, that is, I cannot paste it innautilus
withctrl+v
. However, if I pressctrl+c
after selecting a file innautilus
, the paste function is available for bothnautilus
andlibreoffice
. It seems thatnautilus
uses another differenttarget
, something likex-special/nautilus-clipboard
. But I cannot figure it out clearly, because specifying thetarget
withx-special/nautilus-clipboard
also does not work. – Simon Dec 06 '20 at 07:07 -
-
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 -
-
xsel
can only deal with text, but I want to deal with files with general type, especially image.xclip
seems to be able to do this, but I do not know exactly how to do it. It seems that I have to specify atarget
inxclip -t
, but I do not know exactly what type oftarget
I should specify. – Simon Dec 05 '20 at 08:01