How to access clipboard using xclip in ubuntu

How to access clipboard using xclip in Ubuntu

A clipboard is non-permanent storage on your computer for data that the user wants to copy from one path to another. Later, you can also paste that data stored in the clipboard to somewhere else as well. Until logging off of the system or cutting/copying something, the data on the clipboard is saved. This might be a word selection, a picture, a file, or any other form of data.

You can also clip text from one section of a document and paste it into another portion of the document or somewhere else in a word processing program. The selected information will be copied and kept in the clipboard till you paste it somewhere. Xclip is a great tool that is used as a clipboard in Ubuntu OS. This article is focussing on how you can install and use Xclip clipboard. Let’s begin:

How
Sponsored
to install Xclip in Ubuntu

You can get the Xclip by typing the below-given command in the terminal:

$ sudo apt install xclip

Text description automatically generated

You can check its feature using the command in the terminal:

$ xclip -help

Text description automatically generated

You can also get additional help on how to use the xclip clipboard using the below-mentioned command in the terminal:

$ man xclip

This command will open up a new window in the terminal where you can find all the functionality of the xclip clipboard. If you are unsure and don’t know how to use this clipboard, you can also take some help from the examples mentioned there by scrolling down a little that can be seen in the image below.

Text description automatically generated

How to use Xclip clipboard in Ubuntu with examples

Let’s take some of the examples of this clipboard for better understanding. Suppose you want to copy the name of any website to the clipboard, and then later, you can also paste it by the following method mentioned below.

Text description automatically generated

$ echo “www.Linuxhint.com”|xclip

The above command is used to copy the website name, “www.Linuxhint.com” in this case, to the xclip clipboard. The second command is mentioned below:

$ xclip -o

It is used to paste the content present in the clipboard displayed on the third line of the terminal.

Suppose you want to display the date and time using the clipboard, execute the command mentioned below:

$ date|xclip

Text description automatically generated

How to copy the content of a text file using the xclip clipboard in Ubuntu OS

Now let’s take another example of copying the content of any text file and then paste it onto the terminal. For this approach, create the text file first which you can do by using any text editor. In our case, we are using the “VIM” text editor. You first need to install it if you hav’nt then use the command mentioned below:

$ sudo apt install vim

After its installation, the next step is to create a text file with some content inside it. Use the below-mentioned to create a file:

$ vim testfile.txt

This will open a vim editor with a file name of “testfile.txt” to write anything that can be seen below.

Text description automatically generated

Here “:wq” is used to save and quit the vim editor. Now, as the file is saved, the next step is to move the content of the text file to the clipboard and then later paste the content as well. Use the command as shown below:

See also  Ubuntu Weekly Newsletter Issue 723
$ cat textfile.txt|xclip

Text description automatically generated

The first command will copy the content to the clipboard. Later you can also access the file’s content from the clipboard that has already been discussed before. You can also press the mouse’s middle button to paste the clipboard’s content instead of typing the command $xclip -o, but sometimes we don’t have the mouse as we are working with a laptop mousepad or using the mouse having two buttons only. So, it is not always recommended.

Conclusion

A clipboard is a great tool where the copied data or information from any text file, a picture can be stored, and later that information can be retrieved when needed. It allows you to transfer text and files throughout your system with ease. A lot more can be done to make it easier to use and add new features. All of this can be done using the Xclip clipboard. All you need to do is install it and later understand its functionality by thoroughly reading this article.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply