如何在终端(linux)中将文件复制到剪贴板 [英] How do I copy a file to the clipboard in the terminal (linux)

查看:965
本文介绍了如何在终端(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


  1. 剪贴板中没有文件

  2. 我要做什么:(使用终端将文件复制到剪贴板)。就像右键单击文件并选择副本一样。 (test.txt已在桌面上)

  3. 现在文件位于剪贴板中,我可以将其粘贴到任何地方

  4. 文件已粘贴

  1. No file in clipboard
  2. 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)
  3. Now the file is in the clipboard and I can paste it anywhere
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆