Copy and paste text in a Linux terminal

When working with the Terminal, we sometimes need to copy a long command, file name or text from the Internet, a workbook, or simply from some text file. You may have noticed that simple insert control, Ctrl + V, does not work in the Terminal. We all know that to copy text you need to select it and then click Ctrl + C (for copying) or Ctrl + X (for cutting); so how do we paste the selected text into the terminal? In this tutorial, we will show you how to do this with a few examples that we used in Ubuntu 18.04.

Example 1: Copying a file name to a command in Terminal

A few days ago I needed to install the Google Chrome .deb package, which I downloaded via a web browser on my system. I wanted to install it using the dpkg command from the terminal. When I entered the command, I wanted to make sure that I provided the exact name of the .deb package file. Therefore, I right-clicked the file and selected its name in the Properties window, and then copied it to the clipboard via Ctrl + C,

Copy file name to command in Terminal

Then I opened Terminal and pasted the file name in my command, right-clicking in the right place and then choosing Insert from the menu as shown below:

Paste text with right mouse button

In the following figure, you can see how the text was inserted into my command. That way, I was able to make sure I chose the exact file name to install.

pasted text

Example 2: Insert a huge fragment of text from a text editor into a terminal file

Suppose you are working on a text file in the Nano editor and you need to copy a huge piece of text from a graphical text editor into this file. You can simply do this by selecting the text in a graphical text editor and copying it to the clipboard via Ctrl + C following:

Copy large text.

Then you can paste this text into the Nano Editor file in the Terminal by right-clicking in the right place and choosing Insert from the menu as follows:

Paste a piece of text into the command line

The copied text will be pasted into your Nano text file as follows:

The result is shown in the nano editor.

Example 3: Insert a long / complex command into the Terminal

Suppose that you practice with one of our study guides from the Internet and want to make sure that you execute the exact command in the Terminal without any errors. Let’s try to run the following command, which allows you to view the history of commands along with the date and time stamp.

$ export HISTTIMEFORMAT='%F %T '

Instead of re-entering the command, you can simply copy it from this manual and paste it into the terminal by right-clicking and selecting “Paste” from the menu.

Now, when you run this command and then the history command, you will see the output with the exact date and time format that you set in our manual.

Using HISTTIMEFORMAT

These are just a few examples where you can use text insertion in Terminal. When you start using this skill, you can save a lot of time and effort required for re-entering text or a command in the Terminal.

Copy and paste text in a Linux terminal

Sidebar