- Windows/Mac/Linux/ssh如何将shell内容输出到剪贴板
- Mac
- Linux
- Windows
- 参考
如何将输出直接复制至剪切板?在不同的系统中,所使用的命令是不同的。
Mac// 将输出复制至剪贴板 $ echo "hello mac" | pbcopy // 将文件中的内容全部复制至剪贴板 $ pbcopy < remade.md // 将剪切板中的内容粘贴至文件 $ pbpaste > remade.mdLinux
Linux 用户需要先安装 xclip,它建立了终端和剪切板之间的通道。
// 查看剪切板中的内容 $ xclip -o $ xclip -selection c -o // 将输出复制至剪贴板 $ echo "hello xclip" | xclip-selection c // 将文件中的内容全部复制至剪贴板 $ xclip -selection c remade.md // 将剪切板中的内容粘贴至文件 $ xclip -selection c -o > remade.md
或者直接使用xsel命令:
// 将输出复制至剪贴板 $ echo "hello linux" | xsel // 将文件中的内容全部复制至剪贴板 $ xsel < remade.md
需要注意的是:xsel、xclip 命令是在 X 环境下使用的,所以远程连接服务器时使用会报异常:
xclip error can't open display (null)
ssh如果想要复制到剪贴板的话,可以通过nc开一个端口,把文本传回本机,然后在本机xclip。
# linux nc xxx 5556 | xcopy # mac nc xxx 5556 | pbcopy # server cat large-file.txt | nc -l 5556Windows
// 将输出复制至剪贴板 $ echo "hello windows" | clip // 将文件中的内容全部复制至剪贴板 $ clip < remade.txt参考
Windows/Mac/Linux 如何将内容输出到剪贴板
Exposing Your Clipboard Over SSH



