Linux terminal with copy paste

How to Copy Paste in Linux Terminal [For Absolute Beginners]

Last updated October 29, 2020 By Abhishek Prakash 27 Comments

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.

Читайте также:  Сжать диск mac os

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.

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.

Like what you read? Please share it with others.

Источник

Буфер обмена в Linux (копирование и вставка)

Хочу рассказать о некоторых особенностях буфера обмена в Linux. О буфере копирования и про буфер выбора (первичный буфер), а также про копирование и вставку текста в терминале.

Буфер копирования

Стандартно для копирования и вставки объектов в Linux используются сочетания клавиш Ctrl+C и Ctrl+V. При копировании текст (или любой другой объект) в таком случае попадает в обычный буфер копирования. Затем вы можете вставить этот текст в другом месте.

Буфер выбора (первичный буфер)

В Linux существует еще буфер выбора или первичный буфер. Текст, который вы выделяете в любой программе, автоматически попадает в буфер обмена! Это удобно, выделил текст, открыл другое окно и вставил этот кусок текста. Есть некоторые исключения, но они незначительны. Например, у меня в Ubuntu это не работает, если программа использует JVM (Java Virtual Machine).

Кстати, именно этим объясняется следующие поведение. Вы выделили текст в программе, затем открыли другую программу и выделили какой-нибудь текст в ней. После этого, выделение текста в первой программе автоматически снимется, а текст который вы выделили последним, попадет в буфер выбора.

Копирование и вставка в терминале

В терминале для копирования и вставки не работают стандартные сочетания Ctrl+V, Ctrl+C. Это связано с тем, что исторически Ctrl+C это сочетание клавиш для прерывания текущего процесса. Поэтому, для копирования и вставки при работе в терминале используются сочетания Ctrl+Insert и Shift+Insert соответственно. В Gnome терминале и, наверное, во многих других также работают сочетания Shift+Ctrl+C и Shift+Ctrl+V. Они же указаны в главном меню программы в разделе Правка.

Также в терминале работают сочетания клавиш Ctrl+U, чтобы вырезать текст; и Ctrl+Y для вставки текста. Сочетание Ctrl+U работает особенным образом — в буфер копируется вся текущая строка, введенная в терминале, независимо от того, выбрали вы какой-нибудь текст мышкой или нет, а сама строка пропадает с экрана.

Источник

How to Copy and Paste Text, Files and Folders in Linux Terminal

Copying and pasting is one of the most used actions on a computer. While it is easy to do so with the Ctrl + C and Ctrl + V keyboard shortcuts, on the Linux terminal it is not so straightforward. You have several options to get the job done. Here is how you can copy and paste text, files and directories in Linux terminal.

Читайте также:  Низкоуровневое форматирование жесткого диска linux

Also read: How to Easily Rename Files in Linux

Copy and Paste Text

If you just want to copy a piece of text in the terminal, all you need to do is highlight it with your mouse, then press Ctrl + Shift + C to copy.

To paste it where the cursor is, use the keyboard shortcut Ctrl + Shift + V .

The Paste shortcut also applies when you copy a section of text from a Word document (or any other application) and want to paste it in the terminal. For example, you can copy a command from a web page in your browser and use the Ctrl + Shift + V shortcut to paste it in the terminal.

Copy and Paste a Single File

Any time you want to copy a file or folder in the Linux command line, the above keyboard shortcut won’t work. You have to use the cp command. cp is shorthand for copy. The syntax is simple, too. Use cp followed by the file you want to copy and the destination where you want it moved.

That, of course, assumes that your file is in the same directory you’re working out of. You can specify both.

You also have the option of renaming your file while copying it. Specify the new name in the destination.

Copy and Paste a Folder and Its Contents

In order to copy a folder and its contents, you’re going to need to tell the cp command to copy recursively. That’s simple enough with the -r flag.

All the rest of your syntax is exactly the same. The -r flag serves to tell cp that it’s working with a directory and should copy its contents.

If you want the paste action to overwrite existing files, you can add the -f flag:

Also read: How to Compress Files with zstd Utility in Linux

Copy and Paste Multiple Files

You can also copy multiple files. The Linux command line lets you target multiple items at once with brackets <> . You can use them to list the names of each file to be copied separated by commas.

All three files of differing file types will be copied to the Documents directory.

Copy and Paste All Files of the Same Type

If you have a ton of files of the same type to copy, you can use the wildcard character * . The asterisk/wildcard tells the Linux command line to accept absolutely anything in that place. So, if you tell Linux to copy *.jpg , it’ll copy all JPG files, regardless of the name or whatever comes before the .jpg part.

If you want to use multiple file types, say JPG and PNG, you can use the brackets from before.

Move a File or Folder

If you came here looking to move a file from one place to another without making a duplicate, you can do that easily too, but moving a file requires the mv command. The syntax is very similar to cp.

Similarly, you can also rename it.

There is one major difference, though. You don’t need the -r flag to move a whole folder.

That’s all there is to it. You’re ready to start copying and moving your files from the command line. You can see that the command line way can be very efficient in some situations.

Want more pointers on the Linux command line? Here’s how to check sudo history or find out what the chmod 777 command does to your file permission.

Image credit: Copy – Paste by DepositPhotos

Источник

How to copy and paste a file?

I want copy and paste a file. The name of the file is mkoctfile.m .
The path of this file is:

I want to paste it to the following path

I have made the directory by using following commands:

sudo su mkdir -p /usr/bin/mkoctfile-3.2.4

but I don’t know how to copy and paste mkoctfile.m in this path.

Читайте также:  Что такое не установлен dvd декодер для windows

Please tell me what command I have to use.

3 Answers 3

Use the cp command to copy a file, the syntax goes cp sourcefile destinationfile . Use the mv command to move the file, basically cut and paste it somewhere else.

The exact syntax you would use for your example is:

For more information on the cp or mv commands you can run:

To view the manual pages

Go to that directory from where you want to copy file i.e /usr/bin/octave/3.2.4/m/miscellaneous

../../../ means you are going backward to bin folder and type whatever directory in which you want to copy your file.

You can cut, copy, and paste in CLI intuitively like the way you usually did in the GUI, like so:

  • cd to the folder containing files you want to copy or cut.
  • copy file1 file2 folder1 folder2 or cut file1 folder1
  • close the current terminal.
  • open another terminal.
  • cd to the folder where you want to paste them.
  • paste

To be able to do so, make sure you have installed xclip and readlink . Then, append these functions to the end of your

If you don’t know what .bashrc file is and never modify it before, just open the file explorer, go to Home, press Ctrl+H (show hidden files), search for .bashrc and open it with a text editor like gedit.

Note

By using the above script, you are overriding the default functionality of these commands:

  • copy is a reserved PostgreSQL command.
  • cut and paste are reserved Linux command.

If you use one of those commands default functionality, just modify the script function names accordingly. For example, use p instead of paste .

Источник

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

Источник

Оцените статью