我如何才能管道输出的命令到我的剪贴板,并粘贴回来时,使用终端?例如:
cat file | clipboard
我如何才能管道输出的命令到我的剪贴板,并粘贴回来时,使用终端?例如:
cat file | clipboard
当前回答
只是为了覆盖一个边缘情况:),因为问题标题问(至少现在)如何将命令的输出直接复制到剪贴板。
我经常发现,在命令已经执行并且我不想或不能再次执行之后,复制命令的输出是很有用的。
对于这个场景,我们可以使用gdm或类似的鼠标实用程序并使用鼠标进行选择。apt-get安装gdm,然后右键单击或Cntrl+Shift+c和Cntrl+Shift+v组合在终端进行复制和粘贴
Or, which is the preferred method for me (as the mouse cannot select properly inside one pane when you have multiple panes side by side and you need to select more than one line), using tmux we can copy into the tmux buffer using the standard [ , space , move to select , enter or you can select a block of code. Also this is particularly useful when you are inside one of the lanes of the cli multiplexer like tmux AND you need to select a bunch of text, but not the line numbers (my vim setup renders line numbers)
在此之后,您可以使用命令:
tmux save-buffer - | xclip -i
当然,您可以将其命名为您喜欢的名称,或者直接绑定到tmux配置文件中
这只是给您一个概念性的答案,以覆盖这种不可能再次执行命令的边缘情况。如果您需要更具体的代码示例,请告诉我
干杯
其他回答
在Wayland上的xcopy似乎不工作,使用wl-clipboard代替。 比如戴着软呢帽
sudo dnf install wl-clipboard
tree | wl-copy
wl-paste > file
一种方法是:
安装xclip,例如: Sudo apt-get安装xclip 管道输出到xclip复制到剪贴板: Cat文件| xclip 将刚才复制的文本粘贴到X应用程序中: xclip - o
要粘贴除X应用程序之外的其他地方,例如浏览器窗口中网页的文本区域,请使用:
cat file | xclip -selection clipboard
考虑创建一个别名:
alias "c=xclip"
alias "v=xclip -o"
为了了解这有多有用,假设我想在一个新的终端窗口中打开我的当前路径(在某些系统中可能有其他的方法,如Ctrl+T,但这只是为了说明目的):
Terminal 1:
pwd | c
Terminal 2:
cd `v`
注意v周围的' ',这首先将v作为命令执行,然后将其替换为cd使用。
只复制内容到X剪贴板
cat file | xclip
一样:
your_command_which_gives_output | pbcopy
WSL / GNU/Linux(需要xclip包):
your_command_which_gives_output | xclip -sel clip
Git Bash在Windows:
your_command_which_gives_output | clip
在安装了xclip的Linux下:
Xclip -选择剪贴板<文件
在OS X上,使用pbcopy;Pbpaste的方向相反。
pbcopy < .ssh/id_rsa.pub