如何将命令的输出直接复制到剪贴板中? [英] How can I copy the output of a command directly into my clipboard?
问题描述
在使用终端时,如何将命令的输出传递到剪贴板中并粘贴回去?例如:
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
的16 kB程序:
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屋!