How to copy text in terminal
How to copy text in terminal
Copying text from a terminal
Most mature terminal emulators permit users to copy or save their contents.
Contents
General approach
Terminals without CLIPBOARD selection
Some emulators do not support the CLIPBOARD selection natively, and copy data to the PRIMARY selection. For them xclip may be used:
The above command reads data from the PRIMARY selection and writes it to CLIPBOARD selection.
Other clipboard managers such as autocutsel provide automatic synchronization between selection buffers.
Intercepting commands output
Use tee to intercept the output of a command.
After the command is executed, output-file will contain its output, while having displayed the output at the same time.
Accessing Linux terminal backlog
Comparison of common emulators
The factual accuracy of this article or section is disputed.
Emulator | Select to PRIMARY | CLIPBOARD | ||||
---|---|---|---|---|---|---|
Key combination | Context menu | Window menu | Select | |||
Alacritty | Yes | Yes | No | No | No | |
aterm AUR | Yes | No | No | No | No | |
eterm AUR | Yes | No | No | No | No | |
germinal AUR | Yes | Yes | Yes | No | No | |
Guake | Yes | Yes | Yes | No | No | |
Konsole | Yes | Yes | Yes | Yes | Optional | |
lilyterm-git AUR | Yes | Yes Ctrl+Delete | Yes | No | No | |
lxterminal | Yes | Yes | Yes | Yes | No | |
mate-terminal | Yes | Yes | Yes | Yes | No | |
mlterm AUR | Yes | Yes | No | No | Yes | |
pantheon-terminal | Yes | Yes | Yes | No | No | |
PuTTY | Yes | No | No | No | No | |
qterminal | Yes | Yes | Yes | Yes | No | |
roxterm AUR | Yes | Yes | Yes | Yes | No | |
rxvt AUR | Yes | No | No | No | No | |
sakura AUR | Yes | Yes | Yes | Yes | No | |
st | Yes | Yes | No | No | No | |
Terminator | Yes | Yes | Yes | No | No | |
terminology | Yes | Yes | Yes | No | No | |
Termite | Yes | Yes | No | No | No | |
Tilda | Yes | Yes | Yes | No | No | |
urxvt | Yes | Yes Ctrl+Alt+c | No | No | Optional | |
xfce4-terminal | Yes | Yes | Yes | Yes | No | |
xterm | Yes | Optional[1] | No | No | Yes | |
Yakuake | Yes | Yes | Yes | No | Optional |
Special cases
putty
The xclip approach works for putty: one just has to remember that the xclip invocation should be done on the local computer (in another terminal), not on the remote machine to which putty is connected.
urxvt
Selecting text to CLIPBOARD requires the selection-to-clipboard perl extension. See Rxvt-unicode#Cut and paste for details.
xterm
Access to the CLIPBOARD selection in xterm requires additional steps.
mlterm
In addition to Ctrl+Shift+c you can use Ctrl+Insert if you do not want to kill processes accidentally.
How to copy-paste on Ubuntu terminal
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:
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:
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.
How to Copy Paste in Linux Terminal [For Absolute Beginners]
I have been using Linux for a decade now and this is why sometimes I take things for granted.
Copy pasting in the Linux terminal is one of such things.
I thought everyone already knew this until one of the It’s FOSS readers asked me this question. I gave the following suggestion to the Ubuntu user:
Use Ctrl+Insert or Ctrl+Shift+C for copying and Shift+Insert or Ctrl+Shift+V for pasting text in the terminal in Ubuntu. Right click and selecting the copy/paste option from the context menu is also an option.
I thought of elaborating on this topic specially when there is no single universal way of copy and paste in the Linux terminal.
How to copy paste text and commands in the Linux terminal
There are several ways to do this.
Method 1: Using keyboard shortcuts for copy pasting in the terminal
On Ubuntu and many other Linux distributions, you can use Ctrl+Insert or Ctrl+shift+C for copying text and Shift+Insert or Ctrl+shift+V for pasting text in the terminal.
The copy pasting also works for the external sources. If you copy a command example from It’s FOSS website (using the generic Ctrl+C keys), you can paste this command into the terminal using the Ctrl+Shift+V into the terminal.
Similarly, you can use Ctrl+shift+C to copy text from the terminal and then use it to paste in a text editor or web browser using the regular Ctrl+V shortcut.
Basically, when you are interacting with the Linux terminal, you use the Ctrl+Shift+C/V for copy-pasting.
Method 2: Using right click context menu for copy pasting in the terminal
Another way of copying and pasting in the terminal is by using the right click context menu.
Select the text in the terminal, right click and select Copy. Similarly, to paste the selected text, right click and select Paste.
Method 3: Using mouse to copy paste in Linux terminal
Another way to copy paste in Linux terminal is by using only the mouse.
You can select the text you want to copy and then press the middle mouse button (scrolling wheel) to paste the copied text.
Please keep in mind that these methods may not work in all the Linux distributions for a specific reason that I explain in the next section.
There is no universal key shortcuts for copy paste in the Linux terminal. Here’s why!
The keybindings for copy-pasting are dependent on the terminal emulator (commonly known as terminal) you are using.
If you didn’t know that already terminal is just an application and you can install other terminals like Guake or Terminator.
Different terminal applications may have their own keybindings for copying and pasting like Alt+C/V or Ctrl+Alt+C/V.
Most Linux terminals use the Ctrl+Shift+C/V keys but if it doesn’t work for you, you may try other key combinations or configure the keys from the preferences of the terminal emulator.
Quick word about Putty
If you use Putty on Linux or Windows, it uses an entire different keybindings. In Putty, selecting a text automatically copies it and you can paste it using right click.
Why Linux terminals do not use the ‘universal’ Ctrl+C and Ctrl+V for
No Linux terminal will give you Ctrl+C for copying the text. This is because by default Ctrl+C keybinding is used for sending an interrupt signal to the command running in foreground. This usually stops the running command.
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2020/09/ctrl-c-linux-300×129.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2020/09/ctrl-c-linux.png» width=»703″ height=»303″ src=»https://itsfoss.com/wp-content/uploads/2020/09/ctrl-c-linux.png» alt=»Ctrl C Linux» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2020/09/ctrl-c-linux.png 703w, https://itsfoss.com/wp-content/uploads/2020/09/ctrl-c-linux-300×129.png 300w» data-lazy-sizes=»(max-width: 703px) 100vw, 703px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2020/09/ctrl-c-linux.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Using Ctrl+C stops a running command in Linux terminal
This behavior has been existing long before Ctrl+C and Ctrl+V started being used for copy-pasting text.
Since the Ctrl+C keys are ‘reserved’ for stopping a command, it cannot be used for copying.
Used Ctrl+S and hanged the terminal?
Most of us use Ctrl+S keys to save changes made to text, images etc. This key is almost universal for saving same as Ctrl+C is for copying.
However, if you enter Ctrl+S in Linux terminal, it will freeze the terminal. No need to close the terminal and start it again. You can use Ctrl+Q to unfreeze the terminal.
Ctrl+S and Ctrl+Q are shortcut keys for flow control.
I know this is elementary for the Sherlock Holmes of the Linux world but it could still be useful to the Watsons.
New or not, you may always use shortcuts in Linux terminal to make your life easier.
Creator of It’s FOSS. An ardent Linux user & open source promoter. Huge fan of classic detective mysteries ranging from Agatha Christie and Sherlock Holmes to Detective Columbo & Ellery Queen. Also a movie buff with a soft corner for film noir.
How to Copy and Paste Commands in the Linux Terminal
In this beginner’s guide, we will show you how to copy and paste command-lines and text while working on the Linux Terminal. Ctrl C and Ctrl V won’t work.
E very time you go across Terminal Tuts on our website, you should be reading usage of lengthy command lines that are to be entered into the Terminal. Obviously, we don’t expect you to type the entire command manually, but rather use copy and paste.
In this beginner’s guide, we will show you how to copy and paste command-lines and text while working on the Terminal.
A bit about Ctrl + C and Ctrl + V Keyboard Shortcuts
We all are used to Ctrl + C and Ctrl + V keyboard shortcuts when copying and pasting text within documents, file & folders copy-paste, so on and so forth. While this shortcuts still work on most of the Linux environment including File Manager, Text Editor, and LibreOffice suites, it won’t work in the Terminal.
There is good reasoning behind this behavior in the Terminal. Ctrl + C is used as an interrupt key in the Bash shell, meaning it cancels the active command or program. For example, I cancelled the password request prompt in the below screen-shot which otherwise would be proceeding until I enter the correct root password.
Cancel Command
Ctrl + V is used to insert the following character. For example, Ctrl + V + R will insert R into the editor.
Ctrl + C to copy and Ctrl + V to paste was introduced in Mac OS in 1983, and in Microsoft Windows 3.x in 1990 for the clipboard session. Unix has been in use much before that. Hence, when the modern Terminal was made, they couldn’t use Ctrl + V for paste function.
In short, the Ctrl key is used in combination with a character to perform special functions in Bash. Hence, modern Terminals need to do something else.
Okay, so how to paste text in the Linux Terminal?
Due to the above-discussed issue, the modern Terminal developers applied Ctrl + Shift + V for paste. Similarly Ctrl + Shift + C for copy function. Alternatively, you can right-click and select paste from the menu for pasting the copied command-line.
Terminal Right-click Menu
How to Copy and Paste in Linux Terminal
For users new to Linux, copying and pasting lines of code into your terminal is an integral part of the learning process. Even for experienced users though, it is often easier and preferable to copy in generic code rather than typing everything out by hand. This not only improves speed but reduces mistakes as well.
However, for users familiar with the generic commands of their Windows or Mac PC, they might be surprised to learn the copy and paste commands in Linux, although similar, aren’t exactly the same. Whether you’re brand new to Linux or simply looking for a refresher course on how to copy and paste, read on to learn the most common methods for copying and pasting within the Linux terminal.
How to Copy and Paste in the Linux Terminal
Depending on the Linux terminal you’re running, which is typical dependent on your Linux distribution, you may have access to multiple methods for copying and pasting.
Copy Command in Linux
To copy text in the Linux terminal, use the command:
Ctrl+Insert
or
Ctrl+Shift+C
As most users are probably familiar with using Ctrl+C on PC (or Command+C on Mac), the second option might be the easiest to adapt to.
Paste Command in Linux
To paste text in the Linux terminal, use the command:
Shift+Insert
or
Ctrl+Shift+V
Since most users are familiar with using Ctrl+V on PC (or Command+V on Mac), the second option listed is probably the easiest to remember.
Copying and Pasting with the Mouse
Assuming your terminal has a full graphical interface, you’ll likely be highlighting the text you’re copying using your computer’s mouse. If preferred, you can also handle all your copying and pasting using the mouse as well.
By highlighting and right-clicking the text you’d like to copy, you can open the context menu and select the option to Copy from the list of options. Alternatively, you can right-click on a new line in your terminal and select Paste, to paste any previously copied text into the terminal.
Additionally, you might also be able to copy and paste in the Linux terminal using the middle-button on your mouse. Whether or not you are able to easily do this will depend on the specific terminal application you are using, as some offer greater mouse functionality than others. Assuming your terminal allows you to use this (and that your mouse has a middle-button), you can copy and paste simultaneously, by highlighting a section of text, and then clicking the middle-button. This will copy the highlighted text from that line and automatically paste it into the terminal at the position where your cursor is currently.
And there you have it! With multiple methods for copying and pasting in Linux, you should be able to copy and paste text easily, regardless of your specific Linux distribution.
Don’t see what you’re looking for? Use the search bar at the top to search our entire Knowledge Base.
The Hivelocity Difference
Seeking a better Dedicated Server solution? In the market for Private Cloud or Colocation services? Check out Hivelocity’s extensive list of products for great deals and offers.
With best-in-class customer service, affordable pricing, a wide-range of fully-customizable options, and a network like no other, Hivelocity is the hosting solution you’ve been waiting for.
Unsure which of our services is best for your particular needs? Call or live chat with one of our sales agents today and see the difference Hivelocity can make for you.