如何将输出直接复制至剪切板?在不同的系统中,所使用的命令是不同的。
Mac
1 2 3 4 5 6 7 8
| // 将输出复制至剪贴板 $ echo "hello mac" | pbcopy
// 将文件中的内容全部复制至剪贴板 $ pbcopy < remade.md
// 将剪切板中的内容粘贴至文件 $ pbpaste > remade.md
|
Linux
Linux 用户需要先安装 xclip
,它建立了终端和剪切板之间的通道。
1 2 3 4 5 6 7 8 9 10 11 12
| // 查看剪切板中的内容 $ xclip -o $ xclip -selection c -o
// 将输出复制至剪贴板 $ echo "hello xclip" | xclip-selection c
// 将文件中的内容全部复制至剪贴板 $ xclip -selection c remade.md
// 将剪切板中的内容粘贴至文件 $ xclip -selection c -o > remade.md
|
或者直接使用xsel
命令:
1 2 3 4 5
| // 将输出复制至剪贴板 $ echo "hello linux" | xsel
// 将文件中的内容全部复制至剪贴板 $ xsel < remade.md
|
需要注意的是:xsel、xclip 命令是在 X 环境下使用的,所以远程连接服务器时使用会报异常:
1
| xclip error can't open display (null)
|
Windows
1 2 3 4 5
| // 将输出复制至剪贴板 $ echo "hello windows" | clip
// 将文件中的内容全部复制至剪贴板 $ clip < remade.txt
|