brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: xclip puts command output on the Linux clipboard

Clipboard
~/tips/tip-linux-xclip-clipboard

xclip -selection clipboard < ~/.ssh/id_ed25519.pub

Copy a file or command output without selecting it with the mouse.

Selecting forty lines of terminal output by dragging is a small misery. On a Linux desktop with X11, xclip takes them from a pipe.

sudo apt install xclip
xclip -selection clipboard &lt; ~/.ssh/id_ed25519.pub
journalctl -b -p err | xclip -selection clipboard

The -selection clipboard part matters. By default xclip uses the primary selection, which is the one you paste with the middle mouse button, so Ctrl+V gives you something else and you think it failed.

To print what is on the clipboard, add -o:

xclip -selection clipboard -o

I’d make a short alias for the long form, since nobody types it with joy. -rmlastnl is worth knowing too: it drops a final newline, which stops a pasted command from running before you’ve looked at it.

xclip stays in the background to serve the text until something else takes over the clipboard, so don’t be surprised to see the process. It needs a graphical session: over a plain SSH login there is no display to talk to. And on a Wayland desktop use wl-copy instead. Be careful with passwords, since clipboard managers like to remember them.

Further reading: xclip(1) manual page

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Clipboard tips uname -r | wl-copy dir | clip "+p paste from the clipboard Command-C copy on the Mac cat ~/.ssh/id_ed25519.pub | pbcopy All Clipboard tips (6) All topics

Link