How to copy text from the terminal to the clipboard.

Posted: June 26, 2016. At: 8:33 PM. This was 1 year ago. Post ID: 9362
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

To copy text to the clipboard from the Linux command line in Xorg, we need to install a nice utility called xclip. This will allow us to copy text from the terminal to the clipboard.

Install xclip.

[email protected]:~$ sudo apt install xclip

Then create the bash alias we need for this to work.

[email protected]:~$ alias xclip="xclip -selection c"

Now copy some sample text to the clipboard.

[email protected]:~$ echo "Hello Testing." | xclip

That is how easy this is to do. This way it is easy to redirect output of a command or the contents of a text file to the clipboard. Very useful for those of you that use the terminal a lot.

No comments have been made. Use this form to start the conversation :)

Leave a Reply