It’s quite annoying when I know the command I can use to copy the content on a terminal to clipboard. I know, I can run man xclip, but I think it’s still easier for me to visit this page and see how to do it.

For example, I want to copy the content of my ssh keypair, ed2559.pub, to clipboard, and here how it can be done:

➜ xclip -sel clip < ~/.ssh/id_ed25519.pub 

Or:

➜ cat ~/.ssh/id_ed25519.pub | xclip -sel c
  • -sel or -selection: specify which X selection to use, options are “primary” to use XA_PRIMARY (default), “secondary” for XA_SECONDARY or “clipboard” for XA_CLIPBOARD
  • c or clip or clipboard: copy the selection to clipboard

The xclip command has many other cool options, please check man xclip for more info.

Reference: