exp: Linux xsel命令(剪切板操作指令)
#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
参考//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>.
还没有评论,来说两句吧...