Linux: xclip,pbcopy,xsel用法 terminal 复制粘帖 (mac , ubuntu)
2015-03-03 19:29
459 查看
http://justcoding.iteye.com/blog/1829963
1. Windows下
使用系统自带的
# 位于
示例:
C代码
echo Hello | clip
# 将字符串Hello放入Windows剪贴板
dir | clip
# 将dir命令输出(当前目录列表)放入Windows剪贴板
clip < README.TXT
# 将readme.txt的文本放入Windows剪贴板
echo | clip
# 将一个空行放入Windows剪贴板,即清空Windows剪贴板
2. Ubuntu下
ubuntu下的用户可以只用apt-get来安装:
C代码
sudo apt-get install xclip
其他发行版的用户可以选择自己的安装方式,也可以用源码编译安装,xclip项目的主页是:http://sourceforge.net/projects/xclip/
xclip可以将内容输出到‘X’的剪切板中,比如:
C代码
echo "Hello, world" | xclip
执行这个命令后你就可以用鼠标中键来在X程序中将内容粘贴出来。但是更多的时候,我们需要不仅仅把内容输出到‘X’的剪切板中,而是希望可以在
GUI程序 中用ctrl + v也可以粘贴(比如,输出到gnome的剪切板中),下面这段命令就可以让你将内容输出到gnome的剪切板中:
C代码
echo "Hello, world" | xclip -selection clipboard
再在一个GUI程序中按下ctrl + v,看下是不是粘贴上去了呢?顺着这个命令,我也重新写了一下ifconfig,让它在执行后输入内容到终端的同时,也将ip地址输出到剪切板中,因为通常情况下,查看ifconfig就是为了获取机器的ip地址:
C代码
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'
或者
C代码
xclip -sel clip < file
此时你就可以在网页等编辑框CTRL+V了。
项目主页: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下
使用
示例:
C代码
cat README.TXT | xsel
cat README.TXT | xsel -b # 如有问题可以试试-b选项
xsel < README.TXT
# 将readme.txt的文本放入剪贴板
xsel -c
# 清空剪贴板
4. Mac下
使用
示例:
C代码
echo 'Hello World!' | pbcopy
# 将字符串Hello World放入剪贴板
C代码
cat myFile.txt | pbcopy
C代码
pbpaste > file.txt
要复制结果又想看到命令的输出
命令的结果输出时,如果给复制命令(即上面提到的命令clip、xsel、pbcopy)那么命令输出就看不到了。如果你想先看到命令的输出,可以下面这么做。
C代码
$ echo 'Hello World!' | tee tmp.file.txt
Hello World!
$ xsel < tmp.file.txt
$ rm tmp.file.txt
即先使用
复制SSH的公有KEY
使用下面的命令:
C代码
$ pbcopy < ~/.ssh/id_rsa.pub
注:不同系统使用不同的复制命令。避免用文本编辑器打开这个文件、选中文本、CTRL + C这样繁琐操作。
1. Windows下
使用系统自带的
clip命令。
# 位于
C:\Windows\system32\clip.exe。
示例:
C代码
echo Hello | clip
# 将字符串Hello放入Windows剪贴板
dir | clip
# 将dir命令输出(当前目录列表)放入Windows剪贴板
clip < README.TXT
# 将readme.txt的文本放入Windows剪贴板
echo | clip
# 将一个空行放入Windows剪贴板,即清空Windows剪贴板
2. Ubuntu下
ubuntu下的用户可以只用apt-get来安装:
C代码
sudo apt-get install xclip
其他发行版的用户可以选择自己的安装方式,也可以用源码编译安装,xclip项目的主页是:http://sourceforge.net/projects/xclip/
xclip可以将内容输出到‘X’的剪切板中,比如:
C代码
echo "Hello, world" | xclip
执行这个命令后你就可以用鼠标中键来在X程序中将内容粘贴出来。但是更多的时候,我们需要不仅仅把内容输出到‘X’的剪切板中,而是希望可以在
GUI程序 中用ctrl + v也可以粘贴(比如,输出到gnome的剪切板中),下面这段命令就可以让你将内容输出到gnome的剪切板中:
C代码
echo "Hello, world" | xclip -selection clipboard
再在一个GUI程序中按下ctrl + v,看下是不是粘贴上去了呢?顺着这个命令,我也重新写了一下ifconfig,让它在执行后输入内容到终端的同时,也将ip地址输出到剪切板中,因为通常情况下,查看ifconfig就是为了获取机器的ip地址:
C代码
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'
或者
C代码
xclip -sel clip < file
此时你就可以在网页等编辑框CTRL+V了。
项目主页: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命令。
示例:
C代码
cat README.TXT | xsel
cat README.TXT | xsel -b # 如有问题可以试试-b选项
xsel < README.TXT
# 将readme.txt的文本放入剪贴板
xsel -c
# 清空剪贴板
4. Mac下
使用
pbcopy命令。 # 对应有个
pbpaste命令。
示例:
C代码
echo 'Hello World!' | pbcopy
# 将字符串Hello World放入剪贴板
C代码
cat myFile.txt | pbcopy
C代码
pbpaste > file.txt
要复制结果又想看到命令的输出
命令的结果输出时,如果给复制命令(即上面提到的命令clip、xsel、pbcopy)那么命令输出就看不到了。如果你想先看到命令的输出,可以下面这么做。
C代码
$ echo 'Hello World!' | tee tmp.file.txt
Hello World!
$ xsel < tmp.file.txt
$ rm tmp.file.txt
即先使用
tee命令把输出输到控制台和一个文件中。命令执行完成后,再把输出的内容放到剪贴板中。
复制SSH的公有KEY
使用下面的命令:
C代码
$ pbcopy < ~/.ssh/id_rsa.pub
注:不同系统使用不同的复制命令。避免用文本编辑器打开这个文件、选中文本、CTRL + C这样繁琐操作。
相关文章推荐
- Linux: xclip,pbcopy,xsel用法 terminal 复制粘帖 (mac , ubuntu)
- Linux: xclip,pbcopy,xsel用法 terminal 复制粘帖 (mac , ubuntu)
- Linux: xclip,pbcopy,xsel用法 terminal 复制粘帖 (mac , ubuntu)
- Linux: xclip,pbcopy,xsel用法 terminal 复制粘帖
- Terminal复制粘帖xclip、clip xsel和pbcopy的 用法 (linux,mac ,和ubuntu)
- Terminal的快捷键 for Terminal for Mac OS 10.10, Linux/GNU(Ubuntu, deepin, elementory os,CentOS)
- linux mac os 常用terminal 命令
- [linux]Ubuntu12.1下打开terminal的方式
- linux cp命令参数及用法详解---linux 复制文件命令cp
- linux cp命令参数及用法详解---linux 复制文件命令cp
- linux scp命令参数及用法详解--linux远程复制拷贝命令使用实例
- 解决virtualbox复制ubuntu后改变mac地址不能识别网卡问题
- Linux 判断32或64位的方法,适用于Ubuntu & Mac
- 转--配置linux下dircolors,ls命令和mac下iTerm2的颜色,让终端(iTerm2或Terminal)也色彩缤纷
- (Mark) (Ubuntu)Ubuntu 12.04 LTS 添加虚拟网卡设置硬件MAC地址 (Linux) (MAC)
- Linux 下查看局域网内所有主机IP和MAC(及nmap的用法)
- linux 之 snprintf函数用法 分类: arm-linux-Ubuntu 2013-07-30 09:36 1009人阅读 评论(0) 收藏
- [Linux/Mac学习] find用法心得
- 【转】SecureCRT连接Linux时VIM中文乱码、复制粘贴乱码解决办法(Ubuntu+redhat亲测)
- linux cp命令参数及用法详解---linux 复制文件命令cp