Skip to content

Instantly share code, notes, and snippets.

@Brainiarc7
Created April 26, 2017 17:53
Show Gist options
  • Save Brainiarc7/f5eb9a91973b62a0f71b4c4c6fbb9e03 to your computer and use it in GitHub Desktop.
Save Brainiarc7/f5eb9a91973b62a0f71b4c4c6fbb9e03 to your computer and use it in GitHub Desktop.
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.

@dagolinuxoid
Copy link

I often forget the command - it's a useful one. As an alternative cat filename | xclip -se c

@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

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

@willsilvano
Copy link

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 via email

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