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 792 times
2
Simon
- 419
- 3
- 13
-
3Does this answer your question? [A command-line clipboard copy and paste utility?](https://askubuntu.com/questions/11925/a-command-line-clipboard-copy-and-paste-utility) – Maythux Dec 05 '20 at 07:13
-
@Maythux Not exactly, `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 a `target` in `xclip -t`, but I do not know exactly what type of `target` I should specify. – Simon Dec 05 '20 at 08:01
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 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
-
-
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
-
-