If you are switching from a different platform such as Windows or macOS, knowing how much basic tasks differ in the Linux world is a must.
Copying and pasting are one of them.
Sure, you may already know how you'd select text and then copy-paste but what choices you're left with when you don't have access to the cursor?
In this tutorial, I will walk you through two possibilities of how you can copy and paste in an Ubuntu terminal:
- When you have access to the cursor
- When you don't have access to the cursor
So let's start with the first one.
Copy and paste in the Ubuntu terminal (easy methods)
If you are using any Desktop environment or window manager, the cursor must be there and it will make this task pretty easy.
To copy and paste in the terminal, you'd have to follow three simple steps:
- Select text using the mouse pointer
Ctrl + Shift + Cor
Ctrl+Insertto copy the selected text
Ctrl + Shift + Vor
Shift+Insertto paste the selected text
And there you have it.
Alternatively, you can also use the context menu of the terminal to achieve the same results. Let me show you how.
Method 2: Use the context menu for copy-paste in the Terminal
This method is similar to the above but here, you don't have to use the shortcuts but the context menu to copy and paste the text.
To use this method, you'll have to follow 3 simple steps:
- Select text
- Right-click and the context menu will appear. Select
- Move the cursor where to paste, right-click again and select
Pretty simple. Isn't it?
Using screen command to copy paste (complicated method)
If you are using a Ubuntu server directly, you won't be given any desktop environment as the server are meant to be as minimal as possible.
So how would you copy and paste in that situation?
For this purpose, you'd have to install a program called Screen which will let you select and copy any output generated by the command.
And to install Screen, you'd have to use the following command:
sudo apt install screen
Once done, start the screen by simply executing
screen in your terminal window:
Now, you'll see a prompt. Simply hit
Your terminal is ready.
Now, you can execute any command and it will get you the expected output. But this time, you can select the text and copy it without using any mouse cursor.
To do so, you'll have to follow the given simple steps:
- Execute a command to generate output that needs to be copied.
- Enter copy mode by pressing
Ctrl + a + [
- Navigate from where the text needs to be copied
- Press the
Enterkey to start the selection
- Use arrow keys to select text as per your needs
- Hit the
Enterkey again and your text is copied
Control + a + ]to paste the text
Sounds too complex? Let me get more into details.
Here, I will be copying a text file output from the simple text file named
Hello.txt. And to do so, I will be using the cat command:
Simple 2 lines of code!
Now, to activate the copy mode, press
Ctrl + a + [:
As you can see, the copy mode was activated!
From here on, you can use arrow keys to navigate to where the text needs to be copied (it can be selected from any direction so you can also go to the last part of the output).
Once done, press the enter key and use the arrow keys to select the text:
After selecting the text to be copied, hit the
Enter key again to deactivate the copy mode and it will show you how many characters are copied:
Finally, you can use
Control + a + ] to paste the copied text anywhere in the terminal.
For example, here, I copied text from the standard output and pasted it into the nano text editor:
And there you have it!
Do more with shortcuts
If you are just getting started, I would highly recommend you check out our detailed guide on keyboard shortcuts that every user should know:
I hope you will find this guide helpful. Have any suggestions? Drop a comment.