如何将命令的输出直接复制到剪贴板? [英] How can I copy the output of a command directly into my clipboard?

查看:20
本文介绍了如何将命令的输出直接复制到剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用终端时将命令的输出通过管道传输到剪贴板并将其粘贴回?例如:

How can I pipe the output of a command into my clipboard and paste it back when using a terminal? For instance:

cat file | clipboard

推荐答案

我一直想这样做,并找到了一种很好且简单的方法.我写下了完整的程序,以防其他人需要它.

I always wanted to do this and found a nice and easy way of doing it. I wrote down the complete procedure just in case anyone else needs it.

首先安装一个名为 xclip 的 16kB 程序:

First install a 16 kB program called xclip:

sudo apt-get install xclip

然后您可以将输出通过管道传输到 xclip 以复制到剪贴板:

You can then pipe the output into xclip to be copied into the clipboard:

cat file | xclip

要粘贴刚刚复制的文本,应使用:

To paste the text you just copied, you shall use:

xclip -o

为了简化生活,您可以像我一样在 .bashrc 文件中设置别名:

To simplify life, you can set up an alias in your .bashrc file as I did:

alias "c=xclip"
alias "v=xclip -o"

为了看看这有多大用处,假设我想在一个新的终端窗口中打开我当前的路径(可能还有其他方法,比如 Ctrl+T在某些系统上,但这仅用于说明目的):

To see how useful this is, imagine I want to open my current path in a new terminal window (there may be other ways of doing it like Ctrl+T on some systems, but this is just for illustration purposes):

Terminal 1:
pwd | c

Terminal 2:
cd `v`

注意v 周围的` `.这首先将 v 作为命令执行,然后就地替换它以供 cd 使用.

Notice the ` ` around v. This executes v as a command first and then substitutes it in-place for cd to use.

只将内容复制到X剪贴板

cat file | xclip

如果您想粘贴 X 应用程序以外的其他位置,请尝试以下方法:

If you want to paste somewhere else other than a X application, try this one:

cat file | xclip -selection clipboard

这篇关于如何将命令的输出直接复制到剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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