如何在终端(linux)中将文件复制到剪贴板 [英] How do I copy a file to the clipboard in the terminal (linux)
问题描述
我想使用终端将文件复制到剪贴板,例如右键单击文件并选择复制。在gui中。类似于 cp test.txt的内容(无目的地),因此只要需要,我都可以右键单击该文件并将其粘贴到gui中。谢谢
I would like to copy a file to the clipboard with the terminal, like when right clicking a file and selecting "copy" in the gui. Someting like "cp test.txt" (without a destination) so whenever I want, I could right click and paste the file (or files) in the gui. Thank you
- 剪贴板中没有文件
- 我要做什么:(使用终端将文件复制到剪贴板)。就像右键单击文件并选择副本一样。 (test.txt已在桌面上)
- 现在文件位于剪贴板中,我可以将其粘贴到任何地方
- 文件已粘贴
- No file in clipboard
- What I am trying to do: (copy a file to the clipboard with the terminal). Exactly like right clicking a file and selecting copy. (test.txt already on desktop)
- Now the file is in the clipboard and I can paste it anywhere
- File is pasted
推荐答案
您想要实现的目标并非不可能,但似乎没有通用的解决方案。我唯一找到的就是这个问题:从命令行复制文件,粘贴到Gnome窗口中,反之亦然
What you want to achieve isn't impossible, but looks like there isn't any universal solution. The only thing I managed to find was this question: Copy file from commandline, paste into Gnome window or vice-versa.
要在CLI中通过X剪贴板复制和移动文件,请使用 xclip-copyfile
和 xclip-pastefile
。
When you want to copy and move files via the X clipboard in CLI use xclip-copyfile
and xclip-pastefile
.
另外:
cat ~/foo.c | xclip -i -selection clipboard
这将复制文件〜/ foo.c
到CLIPBOARD(没有选择剪贴板
它将复制到PRIMARY)。
This will copy the contents of file ~/foo.c
into CLIPBOARD (without -selection clipboard
it will copy into PRIMARY).
其他系统上的工具会有所不同(例如,在Windows上为 copy
),或者如果您未使用X服务器。
Tools will be different on other systems (e.g. on Windows will be copy
) or if you aren't using X server.
这篇关于如何在终端(linux)中将文件复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!