Copying and Pasting Text onto the Linux Terminal

Copy and paste text to Linux terminal

While working with the Terminal, we sometimes require copying a long command, file name or text from the web, a tutorial, or simply from some text file. You might have observed that the simple pasting control, Ctrl+V does not work in the Terminal. We all know that copying a text requires selecting it and then either pressing Ctrl+C (for copying) or Ctrl+X (for cutting); so how do we paste the selected text in the Terminal? In this tutorial we will show you how to do so through a few examples we ran on Ubuntu 18.04.

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

A few days back I needed to install a .deb package of Google Chrome that I had downloaded through a web browser on my system. I wanted to install it through the dpkg command from the Terminal. While typing the command, I wanted to be sure that I am providing the exact file name of the .deb package. I, therefore, right-clicked the file and selected its name from the Properties and then copied it on my clipboard through Ctrl+C.

Copying a file name to a command in the Terminal

Then I opened the Terminal and pasted the file name in my command by right-clicking at the desired location and then by selecting Paste from the menu as follows:

Paste text with mouse right-click

You can see in the following image how the text has now been pasted in my command. This way I was able to ensure that I chose the exact file name for an installation.

pasted text

Example 2: Pasting a huge chunk of text from a text editor to a Terminal file

Let us suppose you are working on a text file in the Nano editor and need to copy a huge chunk of text from a graphical text editor to this file. You can simply do so by selecting the text from the graphical text editor and copy it to the clipboard through Ctrl+C as follows:

Copy a large text

You can then paste this text into a Nano Editor file in the Terminal by right clicking at the desired location and then selecting Paste from the menu as follows:

Paste the chunk of text to the commandline

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

The result shown in nano editor

Example 3: Pasting a long/complicated command to the Terminal

Suppose you are practicing along with one of our tutorials from the web and want to make sure that you run the exact command on the Terminal, without any mistake. Let us try running the following command that lets you view your command history along with the date and timestamp.

$ export HISTTIMEFORMAT='%F %T '

Instead of re-typing the command, you can simply copy it from this tutorial and paste it in the Terminal by right-clicking and then 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 you have set from our tutorial.


These are just a few examples where you can utilize pasting text to the Terminal. As you start using this skill, you will be able to save a lot of time and effort that is required in re-typing a text or command in the Terminal.