1. Windows下linux
使用系统自带的clip
命令。
# 位于C:\Windows\system32\clip.exe
。ubuntu
示例:bash
echo Hello | clip # 将字符串Hello放入Windows剪贴板 dir | clip # 将dir命令输出(当前目录列表)放入Windows剪贴板 clip < README.TXT # 将readme.txt的文本放入Windows剪贴板 echo | clip # 将一个空行放入Windows剪贴板,即清空Windows剪贴板
2. Ubuntu下app
ubuntu下的用户能够只用apt-get来安装:ssh
sudo apt-get install xclip
其余发行版的用户能够选择本身的安装方式,也能够用源码编译安装,xclip项目的主页是:
http://sourceforge.net/projects/xclip/
xclip能够将内容输出到‘X’的剪切板中,好比:编辑器
echo "Hello, world" | xclip
执行这个命令后你就能够用鼠标中键来在X程序中将内容粘贴出来。可是更多的时候,咱们须要不单单把内容输出到‘X’的剪切板中,而是但愿能够在GUI程序 中用ctrl + v也能够粘贴(好比,输出到gnome的剪切板中),下面这段命令就可让你将内容输出到gnome的剪切板中:oop
echo "Hello, world" | xclip -selection clipboard
再在一个GUI程序中按下ctrl + v,看下是否是粘贴上去了呢?顺着这个命令,我也从新写了一下ifconfig,让它在执行后输入内容到终端的同时,也将ip地址输出到剪切板中,由于一般状况下,查看ifconfig就是为了获取机器的ip地址:this
alias ifconfig='/sbin/ifconfig && echo `/sbin/ifconfig | sed -n 2p | awk "{ print \\$2 }" | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}"` | xclip -selection clipboard'
或者spa
xclip -sel clip < file
此时你就能够在网页等编辑框CTRL+V了。.net
项目主页:http://sourceforge.net/projects/xclip/
命令man page: http://linux.die.net/man/1/xclip
- -i, -in
- read text into X selection from standard input or files (default)
- -o, -out
- prints the selection to standard out (generally for piping to a file or program)
- -f, -filter
- when xclip is invoked in the in mode with output level set to silent (the defaults), the filter option will cause xclip to print the text piped to standard in back to standard out unmodified
- -l, -loops
- number of X selection requests (pastes into X applications) to wait for before exiting, with a value of 0 (default) causing xclip to wait for an unlimited number of requests until another application (possibly another invocation of xclip) takes ownership of the selection
- -d, -display
- X display to use (e.g. "localhost:0"), xclip defaults to the value in $ DISPLAY if this option is omitted
3. Linux下
使用xsel
命令。
示例:
cat README.TXT | xsel cat README.TXT | xsel -b # 若有问题能够试试-b选项 xsel < README.TXT # 将readme.txt的文本放入剪贴板 xsel -c # 清空剪贴板
4. Mac下
使用pbcopy
命令。 # 对应有个pbpaste
命令。
示例:
echo 'Hello World!' | pbcopy # 将字符串Hello World放入剪贴板
cat myFile.txt | pbcopy
pbpaste > file.txt
要复制结果又想看到命令的输出
命令的结果输出时,若是给复制命令(即上面提到的命令clip、xsel、pbcopy)那么命令输出就看不到了。若是你想先看到命令的输出,能够下面这么作。
$ echo 'Hello World!' | tee tmp.file.txt Hello World! $ xsel < tmp.file.txt $ rm tmp.file.txt
即先使用
tee
命令把输出输到控制台和一个文件中。命令执行完成后,再把输出的内容放到剪贴板中。
复制SSH的公有KEY
使用下面的命令:
$ pbcopy < ~/.ssh/id_rsa.pub
注:不一样系统使用不一样的复制命令。避免用文本编辑器打开这个文件、选中文本、CTRL + C这样繁琐操做。