它是可能的管道到/从剪贴板在Bash?
无论是连接到设备手柄还是使用辅助应用程序,我都找不到任何东西。
例如,如果/dev/clip是一个连接到剪贴板的设备,我们可以这样做:
cat /dev/clip # Dump the contents of the clipboard
cat foo > /dev/clip # Dump the contents of "foo" into the clipboard
它是可能的管道到/从剪贴板在Bash?
无论是连接到设备手柄还是使用辅助应用程序,我都找不到任何东西。
例如,如果/dev/clip是一个连接到剪贴板的设备,我们可以这样做:
cat /dev/clip # Dump the contents of the clipboard
cat foo > /dev/clip # Dump the contents of "foo" into the clipboard
当前回答
在macOS系统下,请使用内置的pbcopy和pbpaste命令。
例如,如果你跑步
cat ~/.bashrc | pbcopy
~/的内容。可以使用Cmd + V快捷方式粘贴bashrc文件。
要保存当前剪贴板到一个文件,将输出pbpaste重定向到一个文件:
pbpaste > my_clipboard.txt
其他回答
在Windows上(使用Cygwin)尝试 Cat /dev/clipboard或echo "foo" > /dev/clipboard如本文所述。
昨天我发现自己遇到了一个问题:“如何在不同的用户会话之间共享剪贴板?”当使用Ctrl + Alt + F7 - Ctrl + Alt + F8切换会话时,实际上,您无法粘贴复制的内容。
我提出了以下快速和肮脏的解决方案,基于一个命名管道。它确实很简陋,但我发现它很实用:
user1@host:~$ mkfifo /tmp/sharedClip
然后在发送终端
user1@host:~$ cat > /tmp/sharedClip
最后,在接收端:
user2@host:~$ cat /tmp/sharedClip
现在,你在第一个终端中输入或粘贴任何东西,并且(在点击返回后),它将立即出现在接收终端中,从那里你可以复制和粘贴你喜欢的任何地方。
当然,这并不是严格地从user1的剪贴板中获取内容,使其在user2的剪贴板中可用,而是需要额外的粘贴和复制单击。
你可以使用大量的剪贴板。我想你可能是一个Linux用户,想把东西放到X Windows主剪贴板中。通常,您想要与之对话的剪贴板有一个实用程序可以让您与之对话。
在X的情况下,有xclip(和其他)。xclip -selection c将数据发送到剪贴板,在大多数应用程序中使用Ctrl + c, Ctrl + V。
如果你在Mac OS X上,有pbcopy。例如,cat example.txt | pbcopy
如果你在Linux终端模式下(没有X),那么查看有剪贴板的gpm或Screen。试试Screen命令readreg。
在Windows 10+或Cygwin下,使用/dev/clipboard或clip。
复制和粘贴到剪贴板在Windows (Cygwin):
See:
$ clip.exe -?
CLIP
Description:
Redirects output of command line tools to the Windows clipboard.
This text output can then be pasted into other programs.
Parameter List:
/? Displays this help message.
Examples:
DIR | CLIP Places a copy of the current directory
listing into the Windows clipboard.
CLIP < README.TXT Places a copy of the text from readme.txt
on to the Windows clipboard.
还有getclip(它可以代替Shift + Ins!)和putclip (echo oeuoa | putclip.exe将其放入clip)存在。
xsel在Debian/Ubuntu/Mint
# append to clipboard:
cat 'the file with content' | xsel -ab
# or type in the happy face :) and ...
echo 'the happy face :) and content' | xsel -ib
# show clipboard
xsel -ob
# Get more info:
man xsel
安装
sudo apt-get install xsel