Firstly make sure that you have the required software installed – xclip.

For Debian-based systems execute the following:

$ apt-get install xclip

For Redhat-based systems run:

$ yum install xclip

For systems with pacman e.g. Arch and Manjaro:

$ pacman -S xclip

Gentoo-based systems:

$ emerge xclip

If you have any trouble installing xclip due to permission levels, prefix the above commands with sudo to escalate yourself momentarily to administrator level.

Now for the actual copy and pasting!

To copy text or the output of a command to the clipboard you need to pipe it to clip -selection clipboard. Following are some examples

 

$ cat readme.txt | xclip -selection clipboard

copies the contents of readme.txt to the clipboard

 

$ ls -1 | xclip -selection clipboard

copies the current directory’s single-columned listing to the clipboard

 

And now for pasting from the clipboard. To paste from the clipboard you need to execute:

$ xclip -o

The best use of this command would be to redirect the output into a file or assign this command to a keyboard shortcut.

:)