Using Linux XCLIP

xclip is a command line utility for setting and getting values on the clipboard using other command’s output or input. Instead of directly using shortcut keys on the terminal, xclip can be used likewise except you have to pipe the output and input from other commands.

In general here’s the three(3) selection for xclip

  • Primary – Used for the 3rd mouse button
  • Secondary – Act’s as an alternative to primary
  • Clipboard – GUI or window-style clipboard using the shortcut keys (ctrl+c, ctrl+shift+v)

Sample Usage

Copying directory listing to clipboard

ls | xclip -selection c
# Alternative
ls | xclip -selection clipboard

Outputing clipboard

xclip -o -selection c

Outputting clipboard content to a file

xclip -o selection c > somefile

Aliasing xclip

Since clipboard‘s the common selection for xclip we can just create an alias on our ~/.bashrc file or system-wide /etc/bashrc, if you’re using bash.


echo "alias xclip='xclip -selection clipboard'" >> ~/.bashrc 
source ~/.bashrc


echo "alias xclip='xclip -selection clipboard'" >> /etc/bashrc
source /etc/bashrc