xclip reference: copy-to-clipboard CLI

xclip is a nifty little utlity to make working in the terminal just a little more comfortable. It allows you to copy the contents of files or the output of other programs to the clipboard.

Here are some use cases:

xclip myfile.txt  # Copy file to clipboard
ls -l | xclip     # Copy program output

Linux has three clipboards: “primary”, “secondary”, and “clipboard”. By default, xclip will feed into the primary clipboard, which you can paste with the middle mouse button, and is overwritten whenever you highlight a piece of text. The third clipboard, called “clipboard”, is the typical Ctrl+C/Ctrl+V clipboard.

Here are a couple of useful flags for xclip:

xclip -f                # Act as filter, outputting stdin to stdout
xclip -select clipboard # Select Ctrl+C/Ctrl+V clipboard
xclip -sel c            # Shorthand for the above
xclip -o                # Output clipboard contents