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 a Debian 10 Buster system.
Why Use the Terminal?
If you are a Terminal-savvy person, you wouldn’t want to leave the comfort of the command line and go somewhere else to do any of your daily technical activities. There is always a way to do almost all of our stuff right inside the Terminal. Using the Terminal makes certain tasks more efficient and, even faster. The command-line tools do not use too many resources and thus form great alternatives to the widely used graphical applications, especially if you are stuck up with older hardware.
Here are some examples where copying text to the Terminal comes in handy; this way you can learn the actual process of copying text in a productive manner.
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.
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:
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 installation.
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:
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:
The copied text will be pasted in your Nano text file as follows:
Another way to paste text to the Terminal is using the Ctrl+Shift+V shortcut. It is basically the alternative to the Ctrl+V shortcut you use in other applications to paste text.
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.
If you want to copy some text from the Terminal, you can do so by selecting it and then using the Ctrl+Shift+C shortcut to copy the text to the clipboard. It is basically the alternative to the Ctrl+C shortcut you use in other applications to copy text.
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.