linux命令行剪贴板_将Linux终端中的命令输出复制到X选择或剪贴板

linux命令行剪贴板linux

xclip is a tool to copy the copy the output of commands from a command line in a terminal to X selection or clipboard. It connects the command line interface and the X selections (clipboard) and is a very useful tool. For example, processing some text in vim in a terminal and then copying it to the browser will be easily handled by xclip.vim

xclip是一个工具,可将命令的输出从终端中的命令行复制到X选择或剪贴板。 它链接命令行界面和X选择(剪贴板),是一个很是有用的工具。 例如,在终端中在vim中处理一些文本,而后将其复制到浏览器将很容易被xclip处理。 浏览器

There are lots good documents and tutorials on the Web including xclip man page, this tutorial and this one. I just give two very common use cases with the command examples. Make sure you have already installed it. On Fedora Linux, you can install it by # yum install xclip.app

Web上有不少不错的文档和教程,包括xclip手册页本教程 教程 。 我仅经过命令示例给出两个很是常见的用例。 确保您已经安装了它。 在Fedora Linux上 ,能够经过# yum install xclipide

将文件(file.txt)的内容复制到其余X应用程序中 (Copying a file (file.txt)’s content to the other X applications )

2 methods here.工具

这里有2种方法。 this

方法1.使用X选择 (Method 1. Use X selection )

First, copying the file content byspa

首先,经过 命令行

$ cat file.txt | xclip

Beside of using cat, you can also use xclip’s -i option.翻译

除了使用cat ,您还能够使用xclip的-i选项。

Then, go the the X application’s input box and hit the middle key or scroll wheel.

而后,转到X应用程序的输入框,而后按中键或滚轮

方法2.使用X剪贴板 (Method 2. Use X clipboard )

First, copying the file content by

首先,经过

$ cat file.txt | xclip -selection c

Then, go the the X application’s input box and press Ctrl + V.

而后,转到X应用程序的输入框, 而后按Ctrl + V。

将剪贴板内容复制到文件(out.txt) (Copying the clipboard content to a file (out.txt) )

First, copying the file content in the X application by Ctrl + C as usually or by selecting them (using your mouse) as usual.

首先,一般按Ctrl + C或一般选择 (使用鼠标选择它们 ,从而在X应用程序中复制文件内容。

Then, saving the content you copied to a file.

而后,将您复制的内容保存到文件中。

$ xclip -o >out.txt

This step is the same no matter you use Ctrl + C or **selection in the previous step.

不管您在上一步中使用Ctrl + C仍是**选择,此步骤都是相同的。

For more options, check the xclip man page.

有关更多选项,请检查xclip手册页

翻译自: https://www.systutorials.com/copying-output-of-commands-in-linux-terminals-to-x-selection-clipboard/

linux命令行剪贴板