xclip: 管理 X 粘贴板

在 X 系统里面,从一个窗口复制一段文字到另一个窗口,有两套机制,分别是 Selections 和 cut buffers。

常用的 copy & paste 是利用的 cut buffers 机制;另外用鼠标选中一段文字,然后在另一个窗口按鼠标中键实现复制,利用的是 selections 机制。selection 又可以分为 master 和 slave selection。

当用鼠标选中一段文件,这段文字就自动被复制到 master selection。然后在另一个地方按鼠标中键,就自动把 master selection 的内容粘贴出来。

当你想复制少量文字的时候,两种方法都是很方便的。但是当复制大段文字的时候就挺麻烦。另外就是你可能会频繁的执行一些复制粘贴工作,不停的用鼠标选中文字,然后再粘贴。这是对手指的折磨。

我忍受不了这种折磨,所以发现了 xclip, 方便的管理 X selections 里面内容的工具。

比如如下命令就把文件 /etc/passwd 的内容复制到 X master selections 里面了。

xclip -i /etc/passwd

然后到别的地方就能复制出来,利用鼠标中键。或者是更舒服的 shift+insert。 我现在最常用的方法是通过键盘绑定来管理 X master selections 的内容。比如 alt+F1 就能把我的 ~/f1 的内容复制到 X master selections,alt+F2 复制 ~/f2 的内容。这样就能把你需要经常用到的内容方便的进行复制粘贴。比如常用的密码啥的。

xclip

Read More:

  • No related posts

12 Comments

  1. 1 小叶 Commented @ 2009-03-26 15:08Reply to this comment

    google!!

  2. 2 Iven Commented @ 2009-03-26 15:12Reply to this comment

    有其他功能么……这个功能看起来……很非主流……

  3. 3 scalarize Commented @ 2009-03-26 15:27Reply to this comment

    我怎么觉得更麻烦了呢。。。

  4. 4 transtone Commented @ 2009-03-26 15:28Reply to this comment

    xsel -b -i < file

  5. 5 hmy Commented @ 2009-03-26 15:35Reply to this comment

    寒,奔三的人了还非主流

  6. 6 glutton Commented @ 2009-03-26 17:34Reply to this comment

    master和slave selection有啥区别? 我每次选中一段文字,想粘贴在另外一个输入框中,但那个框中已经有文字了,所以我不能直接按中键粘贴,而是要先把那些文字删掉,太麻烦了。

  7. 7 freeren Commented @ 2009-03-26 17:59Reply to this comment

    "master和slave selection有啥区别? 我每次选中一段文字,想粘贴在另外一个输入框中,但那个框中已经有文字了,所以我不能直接按中键粘贴,而是要先把那些文字删掉,太麻烦了。"

    这个问题我也是我一直想知道的, 请那位高手解答一下。谢谢!

  8. 8 itux Commented @ 2009-03-26 19:55Reply to this comment

    嗨,说实话,没有clipx好用,

  9. 9 su27 Commented @ 2009-03-26 22:51Reply to this comment

    用这个也可以。 cat id_dsa.pub | pbcopy

  10. 10 ebird Commented @ 2009-03-27 9:00Reply to this comment

    貌似kde4.2里有类似的东东……

  11. 11 transtone Commented @ 2009-03-27 13:33Reply to this comment

    用鼠标的话parcellite挺方便的。

  12. 12 lucilu Commented @ 2009-04-02 19:58Reply to this comment

    我晕。。。这怎么算非主流啊?这个算是经常用的命令好不好。连在别的机器终端的时候。要传啥字符文件。都是这样用的 xclip -i xxxxx 然后在终端上cat > xxxxx ,直接鼠标中键,数据就过去了。这类都是属于小技巧。如user权限下,执行 netstat -antp ,但不是root权限,所以没办法看到process,这个时候你可以sudo !! ,因为你不想用root权限重复再输入一次命令。这类都是shell的技巧操作。资料翻多了,玩多了,自然会发现。