Linux Shell: Copy output into clipboard w/o using the Mouse?

Is it possible to copy the output into the clipboard without using the mouse?

For example, I would like to do something like this:

$ pwd >> clipboard


You can get and use the xclip and xsel commands. Instructions for obtaining and using them are here.

Without any arguments, xclip copies into the primary (middle-click-paste) clipboard instead of the Ctrl-C/Ctrl-V/right-click-context-menu clipboard.

Try echo foo | xclip -selection clipboard to copy some text into the latter.

To output the clipboard to standard out: xclip -selection clipboard -o

The equivalent utility for MacOS is pbcopy (and pbpaste)


If you are on a MAC you can use pbcopy like this:

pbcopy < thing_to_write_to_clipboard