- 将标准输入或从文件得到数据写入X系统的剪切缓冲区,用户就可以在X程序中单击鼠标中键,粘贴刚才xclip得到的数据。
- 将X系统剪切缓冲区中的数据输出到标准输出或文件。
例如在命令行中执行命令“ls | xclip”,然后在firefox的文本输入框中单击鼠标中键,就可以将文件列表粘贴进去。
例如在firefox中用鼠标选中一段话,然后在命令行中执行命令“xclip -o > file.txt”,就将刚才选中的文字保存在文件file.txt中了。
需要注意,X系统有两个剪切缓冲区:
- 主选择区XA_PRIMARY,存放鼠标选中区域的数据(使用鼠标中键可以粘贴此数据)
- 剪贴板XA_CLIPBOARD,对应Windows系统的剪贴板,存放通过菜单命令“编辑/复制”得到的数据(可以使用菜单命令“编辑/粘贴”进行粘贴)
xclip还提供了 xclip-copyfile,xclip-pastefile,xclip-cutfile,顾名思义用于文件的复制粘贴剪切,可以方便地在目录甚至电脑(前体是建立了X11链接)之间复制移动文件。下面的例子摘自xclip的README:
# Copying a file to a remote host
[maggie.lkpg.cendio.se ~]$ echo "A file created on ${HOSTNAME}" > file1
[maggie.lkpg.cendio.se ~]$ xclip-copyfile file1
[sofie.homeip.net ~/doc]$ xclip-pastefile
file1
[sofie.homeip.net ~/doc]$ cat file1
A file created on maggie.lkpg.cendio.se
# Copying an entire tree structure
[sofie.homeip.net ~]$ xclip-copyfile doc
[maggie.lkpg.cendio.se ~/tmp]$ xclip-pastefile
doc/
doc/letter-mom-april.txt
doc/file1
doc/letter-dad-march.txt
# Copying files with preserved path information
[maggie.lkpg.cendio.se ~]$ xclip-copyfile -p /etc/sysconfig/grub
tar: Removing leading `/' from member names
[sofie.homeip.net ~/tmp]$ xclip-pastefile
etc/sysconfig/grub
[sofie.homeip.net ~/tmp]$ ls etc/sysconfig/grub
etc/sysconfig/grub
# Moving files
[sofie.homeip.net ~]$ ls letter-brother-may.txt
letter-brother-may.txt
[sofie.homeip.net ~]$ xclip-cutfile letter-brother-may.txt
[sofie.homeip.net ~]$ ls letter-brother-may.txt
ls: cannot access letter-brother-may.txt: No such file or directory
[sofie.homeip.net ~]$ cd doc
[sofie.homeip.net ~/doc]$ xclip-pastefile
letter-brother-may.txt
ubuntu 8.10带的xclip是0.08版,不支持utf-8。从这里可以下到最新版,我下到的是0.12,使用utf-8没有问题。