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

37 篇文章 0 订阅

#Selection options默认是-p, --primary,所以下面两个是一样的:
xsel
xsel -p

echo 111 | xsel -i
或
echo 111 | xsel -i -p

echo 222 | xsel -i -s
echo 333 | xsel -i -b

xsel -p #结果为111
xsel -s #结果为222
xsel -b #结果为333

xsel -x # 交换p和s
xsel -p #结果为222
xsel -s #结果为111

xsel -c 或 xsel -c -p,#清空-p
xsel -c -s,#清空-s
xsel -c -b,#清空-b


# 复制文件内容到剪切板
cat xxx.txt | xsel -b -i
或
xsel -b -i < xxx.txt
# 验证: 通过wc统计工具看字节数是否相同
xsel -b |wc
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 命令。示例:

cat README.TXT | xsel

# 如有问题可以试试-b选项
cat README.TXT | xsel -b 

# 将readme.txt的文本放入剪贴板
xsel < README.TXT 

# 清空剪贴板
xsel -c

 xsel -o 显示数据

把剪贴板的数据放到新文件
xsel -o > newfile

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


$ xsel --help
Usage: xsel [options]
Manipulate the X selection.

By default the current selection is output and not modified if both
standard input and standard output are terminals (ttys).  Otherwise,
the current selection is output if standard output is not a terminal
(tty), and the selection is set from standard input if standard input
is not a terminal (tty). If any input or output options are given then
the program behaves only in the requested mode.

If both input and output is required then the previous selection is
output before being replaced by the contents of standard input.

Input options
  -a, --append          Append standard input to the selection
  -f, --follow          Append to selection as standard input grows
  -i, --input           Read standard input into the selection

Output options
  -o, --output          Write the selection to standard output

Action options
  -c, --clear           Clear the selection
  -d, --delete          Request that the selection be cleared and that
                        the application owning it delete its contents

Selection options
  -p, --primary         Operate on the PRIMARY selection (default)
  -s, --secondary       Operate on the SECONDARY selection
  -b, --clipboard       Operate on the CLIPBOARD selection

  -k, --keep            Do not modify the selections, but make the PRIMARY
                        and SECONDARY selections persist even after the
                        programs they were selected in exit.
  -x, --exchange        Exchange the PRIMARY and SECONDARY selections

X options
  --display displayname
                        Specify the connection to the X server
  -t ms, --selectionTimeout ms
                        Specify the timeout in milliseconds within which the
                        selection must be retrieved. A value of 0 (zero)
                        specifies no timeout (default)

Miscellaneous options
  -l, --logfile         Specify file to log errors to when detached.
  -n, --nodetach        Do not detach from the controlling terminal. Without
                        this option, xsel will fork to become a background
                        process in input, exchange and keep modes.

  -h, --help            Display this help and exit
  -v, --verbose         Print informative messages
  --version             Output version information and exit

Please report bugs to <conrad@vergenet.net>.

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值