exp: Linux xsel命令(剪切板操作指令)

红太狼 2022-09-03 00:17 303阅读 0赞
  1. #Selection options默认是-p, --primary,所以下面两个是一样的:
  2. xsel
  3. xsel -p
  4. echo 111 | xsel -i
  5. echo 111 | xsel -i -p
  6. echo 222 | xsel -i -s
  7. echo 333 | xsel -i -b
  8. xsel -p #结果为111
  9. xsel -s #结果为222
  10. xsel -b #结果为333
  11. xsel -x # 交换p和s
  12. xsel -p #结果为222
  13. xsel -s #结果为111
  14. xsel -c xsel -c -p,#清空-p
  15. xsel -c -s,#清空-s
  16. xsel -c -b,#清空-b
  17. # 复制文件内容到剪切板
  18. cat xxx.txt | xsel -b -i
  19. xsel -b -i < xxx.txt
  20. # 验证: 通过wc统计工具看字节数是否相同
  21. xsel -b |wc
  22. wc xxx.txt

参考:


inux xsel 拷贝复制命令行输出放在系统剪贴板上

https://www.cnblogs.com/youxin/p/3544807.html

Linux下

首先安装一个名为xsel的包:

  apt-get install xsel

  然后就可以在命令行下操作剪贴板了:)

  这里只贴几个常用的,更多的请参见man文档。

  显示剪贴板中的数据:

  xsel -b -oxsel -b -o

  向剪贴板中追加数据:

  xsel -b -a

(

-b, —clipboard
operate on the CLIPBOARD selection.)

  覆盖剪贴板中的数据:

  xsel -b -i

  例如说,我要将某个文档复制到剪贴板,以前我要打开这个文档,全选后复制,现在我只需要在bash中输入cat filename | xsel -b -i即可,非常方便。

使用 xsel 命令。示例:

  1. cat README.TXT | xsel
  2. # 如有问题可以试试-b选项
  3. cat README.TXT | xsel -b
  4. # 将readme.txt的文本放入剪贴板
  5. xsel < README.TXT
  6. # 清空剪贴板
  7. xsel -c
  8. xsel -o 显示数据
  9. 把剪贴板的数据放到新文件
  10. xsel -o > newfile

参考:http://blog.csdn.net/kodeyang/article/details/12260243


  1. $ xsel --help
  2. Usage: xsel [options]
  3. Manipulate the X selection.
  4. By default the current selection is output and not modified if both
  5. standard input and standard output are terminals (ttys). Otherwise,
  6. the current selection is output if standard output is not a terminal
  7. (tty), and the selection is set from standard input if standard input
  8. is not a terminal (tty). If any input or output options are given then
  9. the program behaves only in the requested mode.
  10. If both input and output is required then the previous selection is
  11. output before being replaced by the contents of standard input.
  12. Input options
  13. -a, --append Append standard input to the selection
  14. -f, --follow Append to selection as standard input grows
  15. -i, --input Read standard input into the selection
  16. Output options
  17. -o, --output Write the selection to standard output
  18. Action options
  19. -c, --clear Clear the selection
  20. -d, --delete Request that the selection be cleared and that
  21. the application owning it delete its contents
  22. Selection options
  23. -p, --primary Operate on the PRIMARY selection (default)
  24. -s, --secondary Operate on the SECONDARY selection
  25. -b, --clipboard Operate on the CLIPBOARD selection
  26. -k, --keep Do not modify the selections, but make the PRIMARY
  27. and SECONDARY selections persist even after the
  28. programs they were selected in exit.
  29. -x, --exchange Exchange the PRIMARY and SECONDARY selections
  30. X options
  31. --display displayname
  32. Specify the connection to the X server
  33. -t ms, --selectionTimeout ms
  34. Specify the timeout in milliseconds within which the
  35. selection must be retrieved. A value of 0 (zero)
  36. specifies no timeout (default)
  37. Miscellaneous options
  38. -l, --logfile Specify file to log errors to when detached.
  39. -n, --nodetach Do not detach from the controlling terminal. Without
  40. this option, xsel will fork to become a background
  41. process in input, exchange and keep modes.
  42. -h, --help Display this help and exit
  43. -v, --verbose Print informative messages
  44. --version Output version information and exit
  45. Please report bugs to <conrad@vergenet.net>.

发表评论

表情:
评论列表 (有 0 条评论,303人围观)

还没有评论,来说两句吧...

相关阅读

    相关 zeroclipboard剪切

    上一篇我介紹了實現添加到剪切板的功能,主要是由python的第三方包引入,今天我要介紹由node引入的.其實他們的實現原理是一樣的. 在項目裏配置這兩個文件 ZeroCl

    相关 剪切clipboard

    工作中遇到的一个问题,在项目系统中复制一段内容,或点击一个按钮,然后将这段内容添加到使用者当前电脑系统的剪切板中.刚开始的时候觉得很迷惑不知如何实现,后来前端开发人员说,她们可