Ubuntu

How to copy-paste on Ubuntu terminal

In user-interface design and human-computer interaction, copy-paste are operations that provide an interprocess communication mechanism for moving data via the user interface of a system. The copy command duplicates the data and saves it to temporary storage (the clipboard). Then this data from the clipboard is pasted into the desired location. The copied data is accessible to any program that supports the functionality and allows itself to transfer data easily.

You may need to write long commands or sentences obtained in a file or on the internet while working on the Ubuntu terminal. You can save your precious time by utilizing copy-pasting techniques rather than entering them word by word. Using the standard keyboard commands Ctrl+c and Ctrl+v, you may have copied and pasted text multiple times in your Ubuntu Graphical User Applications such as LibreOffice, Gedit, OpenOffice. However, you may be surprised to learn that many common keyboard shortcuts do not work in Ubuntu Terminal.

This article will show you how to copy-paste in the Ubuntu terminal using two different methods. The examples below are executed on Ubuntu 20.04; other Linux distributions can also use the same copy-paste approach. Now, let’s get started!

How to copy-paste on Ubuntu terminal using right-click context menu

You need to utilize the mouse to highlight the text; why not use it to copy and paste? You can use the mouse right-click for copy-paste as you do in other Ubuntu applications. For this, select the text you want to copy, then right-click on it, and from the context menu, click on the “Copy” option. You can paste this copied command to the terminal window, any script, or any other document.

Example 1: In the below-given example, we will copy-paste the command executed in the Ubuntu terminal to a document named “testscript”:

Firstly, we have selected the command. After that, utilizing the right-click context menu, we will click on the “Copy” option:

Now, we will paste the copied command in our “testscript” document. Click on the document position, where you want to place the copied command, and then from the right-click context menu, click on the “Paste” option:

Example 2: In Ubuntu, you can also use your mouse’s context menu right-click to copy-paste from a terminal to the other terminal window. For this, select the command and click on the “Copy” option:

Move into the other terminal and paste the selected command in the following way:

All done!

How to copy-paste on Ubuntu terminal using keyboard shortcuts

Most computer users are accustomed to using “CTRL+c” and “CTRL+v” for copy-pasting text. These shortcuts also work on Ubuntu Desktop, but not in the terminal. To copy or paste commands from or to the Ubuntu terminal, you must add the “Shift” key in these keyboard shortcuts.

Rules are simple:

  • To copy text or command from Ubuntu terminal, press “CTRL+Shift+c
  • To paste text or command in Ubuntu terminal, press “CTRL+Shift+v
  • To copy text or command from outside of the Ubuntu terminal, press “CTRL+c
  • To paste text or command in any document or script, press: “CTRL+v

Example 1: In the below-given example, we will try to copy commands from the document “testscript” to our Ubuntu terminal:

First of all, we will select all of the required commands for copying and then press “CTRL+c”:

After that, we will move towards our terminal window and paste the commands in it by pressing “CTRL+SHIFT+v”:

This operation will paste and execute the copied commands in the terminal simultaneously:

If you paste a command into the Ubuntu terminal with a trailing newline, the command will be executed right away. I have discovered that selecting a command by clicking at the end and dragging it to the beginning is the easiest way to avoid this. We will be able to paste commands in the Ubuntu terminal through this selection method without executing it instantly.

Next, we will select the command from the document by using the method mentioned above. After that, press “CTRL+c” to copy it:

Move into your Ubuntu terminal and press “CTRL+Shift+v” to paste the copied command:

The below-given shows that we have successfully pasted the command from our document to the terminal without executing it instantly:

Example 2: How to copy-paste from Ubuntu terminal to a document using keyboard shortcuts
To copy and paste any command from your terminal window; select it by pointing the cursor at the end of it. After that, utilize the mouse right-click button and drag it towards the start of the command. Once you have selected the command, press “CTRL+Shift+c” to copy it:

Next, open up your document where you want to paste the command and press “CTRL+v”. Now the “testscript” document will look like this:

Conclusion

There are always options to copy-paste in the Ubuntu terminal whenever you find yourself reusing any text. In Ubuntu, copy-paste enables you to copy and paste text or commands without retyping them repeatedly. This process also saves your time, which you can invest in other things. In this article, you have learned how to copy-paste in the Ubuntu terminal using two different methods. According to our experience, using keyboard shortcuts for copy-paste is easier than utilizing the mouse right-click menu.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.