Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using xclip to copy terminal content to the clip board on Linux

Using xclip to copy terminal content to the clip board:

Say you want to pipe shell output to your clipboard on Linux. How would you do it? First, choose the clipboard destination, either the Mouse clip or the system clipboard.

For the mouse clipboard, pipe straight to xclip:

echo 123 | xclip

For the system clip board, pipe to xclip and select clip directly:

echo 123 | xclip -sel clip

See the man file of xclip here.

@richarddewit
Copy link

richarddewit commented Jan 14, 2019

The exact parameters for xclip don't really matter, as long as they unambiguously resemble -selection and clipboard, so xclip -sel clip or xclip -se c can all be used, but not xclip -s clipb as -s also resembles -silent.
So the shortest possible command is xclip -se c.

From the manual:

Options can be abbreviated as long as they remain unambiguous. For example, it is possible to use -d or -disp instead of -display. However, -v couldn't be used because it is ambiguous (it could be short for -verbose or -version), so it would be interpreted as a filename.

Note that only the first character of the selection specified with the -selection option is important. This means that "p", "sec" and "clip" would have the same effect as using "primary", "secondary" or "clipboard" respectively.

@aminelch
Copy link

aminelch commented Apr 23, 2019

thank you
i use it as a alia on my zh terminal
alias ccc="xclip -sel clip"

@willsilvano
Copy link

willsilvano commented Jun 28, 2019

Thanks! @aminelch

@dreua
Copy link

dreua commented May 25, 2021

Thanks, just added alias xcli-actual-clipboard='xclip -sel clip' as a reminder & shortcut for future me.

@Brainiarc7
Copy link
Author

Brainiarc7 commented May 25, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment