How do I send console output to the clipboard?
+3
−0
Suppose I have a command that prints to the standard output, like:
$ echo hi
hi
How can I send this to the clipboard instead, as if I selected the output and did Ctrl+C?
3 answers
+3
−0
Works for me
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
alx | (no comment) | Jun 3, 2024 at 10:28 |
On X, echo hi | xsel -ib
seems to work. I can then paste with Ctrl+V. Sometimes I have to repeat it a few times for it to "stick".
2 comment threads
echo(1) appends a newline
(5 comments)
xsel(1) seems simpler than xclip(1)
(2 comments)
+5
−0
Use xclip(1).
For example:
$ printf '%s' foo | xclip;
And now Shift+Insert to paste.
There's a primary selection, a secondary selection, and a clipboard selection, and you can chose between those, which will change the combination of keys for pasting (this also depends on the application where you're pasting). You can also paste with xclip -o
back to the terminal.
0 comment threads
+4
−0
On Wayland, the wl-clipboard
utility wl-copy
is the program you want:
echo hi | wl-copy
0 comment threads