Pipe the standard output (stdout) to the clipboard: xsel and xclip

The xsel and xclip tools are used for copying text to the clipboard. I mostly use this trick to copy the standard output to clipboard, and paste it wherever I need it.

Watch Free Movies

Both xsel and xclip do the same work, you can use only one.

Installing xsel:

Install xsel on Debian based distros: sudo apt-get install xsel

Install xsel on Fedora and CentOS: sudo yum install xsel

Install xsel on OpenSUSE: sudo zypper install xsel

Installing xclip:

Install xclip on Debian based distros: sudo apt-get install xclip

Install xclip on Fedora and CentOS: sudo yum install xclip

Install xclip on OpenSUSE: sudo zypper install xclip

Using xsel or xclip:

Syntax for xsel: command | xsel -ib

Syntax for xclip: command | xclip -sel clip

Example:

$ cat /path/to/file | xsel -ib
OR:
$ cat /path/to/file | xclip -sel clip
Now, paste the copied text with Ctrl – Shift – V.

You can create some aliases to ease up your work:

$ alias copy='xclip -sel clip'
OR:
$ alias copy='xsel -ib'

Now, use it like this:
$ ls | copy
To paste it, press Ctrl – Shift – V .

Make this aliases persistent:

$ echo "alias copy='xsel -ib'" >> ~/.bashrc
OR:
$ echo "alias copy='xclip -sel clip'" >> ~/.bashrc

Scroll to Top