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

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)


I'm afraid there is no such thing as "clipboard" in most linux shells, at least none I know of. There's a clipboard in the X server (if your system has X11, you may access it using xclip command). If you connect to your shell account using some ssh/terminal emulator software, like PuTTy, you can use the clipboard of the system you are using, but that still would be an external clipboard and you might not be able to avoid using mouse.

What I have found is this little neat bash script, found at http://geek.phatus.com/2010/01/create-a-simple-yet-very-useful-bash-clipboard/ . It basically creates a temporary file which serves as a clipboard - you can clear, execute, write etc. your temporary data using a set of commands, which is actually what a clipboard does ;)

Tags:

Linux

Shell

Bash