它是可能的管道到/从剪贴板在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
当前回答
如果您像我一样在没有根权限的Linux服务器上运行,并且没有任何xclip或GPM,您可以通过使用临时文件来解决这个问题。例如:
$ echo "Hello, World!" > ~/clip
$ echo `cat ~/clip`
Hello, World!
其他回答
对于mac,你可以使用这个函数,它使用pbcopy和pbpaste,但更简单:
将此添加到你的.bashrc或.zshrc:
clp() {
if [[ -z "$1" ]]
then
# No input - act as paste
pbpaste;
else
# Input exists - act as copy
echo "$1" | pbcopy;
fi
}
复制使用clp“Content”,粘贴使用clp
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
一种从剪贴板粘贴到文件的方法,不需要任何工具,除了echo。
转义你想要粘贴的文本中的单引号:用“\”替换所有出现的“\”并将结果复制到剪贴板。 输入echo -n ' 按Shift +插入 输入' > filename.txt 按回车键
基本上你是这样做的:
Echo -n复制“text”带“\”单引号“\”转义“> filename.txt”
即使复制的文本有新的行,它也能工作。
你可以使用大量的剪贴板。我想你可能是一个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。
Try
xclip
xclip - command line interface to X selections (clipboard)
man