220

When I copy something to the clipboard and press Ctrl + V in Bash, nothing happens; However, right clicking and selecting Paste does the job.

Why? Is there any reasonable issue (I'm sure there is) behind this behavior in Linux?

15
  • 31
    Shift-Insert also works
    – bonyiii
    May 7, 2012 at 10:57
  • 41
    I prefer Ctrl-Shift-V, personally.
    – amalloy
    May 7, 2012 at 18:46
  • 3
    You can also use Shift + Insert in most shell environments.
    – Fabian
    May 8, 2012 at 9:17
  • 5
    What if you won't have an Insert key? Oct 1, 2013 at 23:46
  • 3
    @BenRacicot, Ctrl-Shift-V also works. Jan 21, 2014 at 11:13

7 Answers 7

405

In the days of physical terminals, session-wide clipboards did not exist, only few programs supported internal copy/paste – often under the name of "buffers" or "kill rings" – and used various different keystrokes. For example, the bash shell uses CtrlK or CtrlU to "kill" (cut), CtrlY to "yank" (paste); this comes from the emacs editor.

CtrlC almost everywhere in Unix was the "interrupt" key, used to cancel the current program or operation. The CtrlV key often meant "verbatim insert" – that is, insert the following character literally without performing any associated action. For example, a normal Esc switches to command mode in the vi editor, but CtrlV, Esc will insert the ESC character into the document.

The use of CtrlC to copy and CtrlV to paste from session-wide clipboard was introduced by Mac OS in 1983 and Microsoft Windows 3.x in 1990. (Earlier Windows versions (1.x and 2.x), as well as IBM OS/2, only supported the IBM CUA keys CtrlIns to copy and ShiftIns to paste; these shortcuts remain supported by all Windows versions.)

When GUIs with clipboard support finally reached Unix, the Ctrl keypresses were already in use by many terminal programs. In addition, the X graphical interface had somewhat different mechanisms: "selections" and "cut buffers". Even now you can select text in one program and insert it using the middle mouse button, without any explicit copy action.

In short, by the time Xterm and GNOME Terminal were written (I'm guessing you use the latter), CtrlV already had a completely different meaning for many years and could not be changed. In addition, an alternative method of copying text – the "selection" – was already present in X11, so explicit copy/paste action was probably considered not as important as it would be in Windows. This means that different keyboard shortcuts had to be selected – for example, most modern terminal programs, like GNOME Terminal, use CtrlShiftC and CtrlShiftV. (If you use Xterm, the same shortcuts can be added manually using the XTerm*vt100*translations Xresource. Rxvt does not have such an option.)

(Most X11 toolkits also support the CUA "copy" and "paste" keys, which do not conflict with terminal programs. Unfortunately, the implementations are rather inconsistent – CtrlIns copies to the "clipboard" in most programs (GTK, Qt4, but ignored by Xaw); however, ShiftIns pastes from the "primary selection" in most GTK and Qt4 programs, but from "clipboard" in Firefox, and from the now-obsolete cut-buffers in the now-obsolete Xaw.)


All that said, some terminals or consoles (in particular, the Windows 10 console) do support these keys. As the Windows console always had a separate "mark/select" mode, CtrlC now also has two meanings based on context – in regular mode it sends an interrupt, in select mode it copies to clipboard (just like Enter used to).

Meanwhile, Windows command-line tools never really used CtrlV for anything, so it was bound to "paste" without disturbing much anything. Doing the same on Unix-like terminals however would be more problematic.

12
  • 12
    Hmm. In Vim, “yank” means copy rather than paste. This seems to make more sense, too. Are you sure about the meaning of this term here? May 7, 2012 at 12:23
  • 13
    Yes, I'm sure. Bash inherits the default shortcuts from their Emacs equivalents. May 7, 2012 at 12:42
  • 4
    @grawity: your last comment is a teenie bit misguided. Bash offers two modes of command-line editing, vim-mode and emacs-mode. It just happens that emacs-mode is the default on most installs. That does raise ambiguity in the use of the term yank, even for bash.
    – rahmu
    May 7, 2012 at 13:46
  • 1
    A-ha! I knew the Vimperator developers made a mistake when they switched <C-v> to i in version 3, but I couldn't quite put my finger on why.
    – Izkata
    May 7, 2012 at 18:08
  • 2
    @Colin: You still missed the distinction between clipboard and X selection. There are several selections (PRIMARY, SECONDARY, CLIPBOARD), but only one of them is usually called a "clipboard" – the CLIPBOARD selection, because that's where Ctrl-C copies to, and that's where Ctrl-V pastes from. The primary selection is not the clipboard. Nov 5, 2016 at 18:14
51

Use CtrlShiftV for pasting.

Ctrl with other chars is usually used by the shell for special functions.

5
  • 5
    So why Linux does not register CTRL+SHIFT for special functions instead; I think copy-paste is more typical by some users than that special functions, right? May 7, 2012 at 7:58
  • 23
    Shells have existed way before there were graphical Terminals and GUIs with cut and paste functionality, so your argument isn't really valid. @YasserZamani
    – slhck
    May 7, 2012 at 8:01
  • 9
    Ctrl+Shift+V is executed by the terminal emulator (assuming you're using GNOME Terminal) and not by bash itself. If you're ever outside a GUI environment, or if you're using another term emulator, this will probably not work. Do not think this command is portable.
    – rahmu
    May 7, 2012 at 13:48
  • @rahmu Oh, had no idea about that. Use only stock Ubuntu installs. Is there a universal command?
    – Akash
    May 7, 2012 at 15:46
  • 2
    There probably isn't one for accessing the clipboard (only Shift+Ins for the primary selection). Even the clipboard itself is an X11 thing, not accessible from tty's. However, Ctrl+Shift+V is supported by GNOME Terminal, Xfce4 Terminal, KDE Konsole; this covers the most popular GUI environments. May 8, 2012 at 11:20
24

Here's your general-purpose copy paste settings with popular terminals:

gnome-terminal (most popular on Linux)
Copy: CtrlShiftC
Paste: CtrlShiftV
Note: Select-to-copy and middle-click to paste also works, but it uses an alternate clipboard.

PuTTY (most popular terminal in Windows)
Copy: (select with mouse, no keyboard interaction)
Paste: Right-click (or more reliably: shiftRight-click)
Note: Apps that take mouse input (like vim and links) can steal Right-click -- shiftRight-click will always work in any app.

OSX Terminal
Copy: AppleC
Paste: AppleV
Note: Apps that take mouse control (like vim and links) may override what it means to select text, in which case copy won't work the way you expect it to. In those cases, hold down Control while you drag the mouse to select. Mouse interaction with apps is disabled by default in your terminal settings, so most people won't even know about this.

5
  • Isn't cmd.exe more popular than PuTTY on Windows? :-)
    – Ben
    May 8, 2012 at 17:09
  • @Ben Not as an SSH terminal.
    – tylerl
    May 8, 2012 at 17:34
  • 1
    No, cmd.exe is not an SSH terminal. That is very true.
    – Ben
    May 8, 2012 at 17:37
  • 4
    @Ben: It is not a terminal at all - only a shell. The default terminal in Windows is the "Windows Console" component of csrss. May 9, 2012 at 4:34
  • @Ben but right click to paste also works on cmd.exe (and is the only way there, if you don't want to open menu > edit > paste) in quick edit mode. There's no shortcut in pre-win10 command prompt
    – phuclv
    Nov 26, 2016 at 10:24
19

It is a deep rooted tradition that the Ctrl key together with a letter generates ASCII control characters found by subtracting 64 from the upper case letter's ASCII value. This calculation maps Ctrl-A to 1, and so on. For instance Ctrl-I is Tab and Ctrl-J is linefeed.

There is no similar tradition for Ctrl-Shift. Ctrl-Shift-V is not expected to produce any specific character.

Terminal emulators must support tradition by transparently passing through the Ctrl convention, letting it appear as character input to the programs being operated through that terminal window. Terminal-based programs map control keys to commands. For example, Bash uses Ctrl-V as a command which means "take the next character literally". This allows you to embed a control character in the command line. If the terminal steals control keys for its own use, such commands become unavailable. So intercepting Ctrl-V for a meta-function is out of the question (at least in a default configuration).

However, terminal emulators are free to intercept Ctrl-Shift-V which isn't expected to generate a character. Ctrl-Shift-V isn't a standard; it's a Gnome Terminal thing (which may be in some other terminals).

On X-based Unix desktops the convention is that no command is needed to copy. You just select the text. And the middle button pastes that text elsewhere. You will find that it works in Xterm, Gnome Terminal and Firefox alike.

Ctrl-V is a Microsoft Windows convention, which is an imitation of Apple-V from the Macintosh.

5
  • 3
    It is not exactly subtraction -- traditionally Ctrl has cleared the 6th and 7th bits of the character; because of this, Ctrl+Shift+letter works identically to Ctrl+Letter in most terminals (unless it is explicitly overriden by the terminal, as in the case of copy/paste shortcuts). May 8, 2012 at 12:18
  • 1
    Because the keys are essentially randomly ordered with respect to the ASCII standard, the program ROM includes several look-up tables that assist in the generation of the ASCII codes. ... Holding own the CONTROL key when another key is pressed causes another table look-up. [VT100 series Technical Manual, 4.4.9.3, Digital].
    – Kaz
    May 10, 2012 at 2:40
  • 1
    @Linger thanks for the edit. It renders nicely, but there is no way I'm typing all these <kbd> tags in future posts.
    – Kaz
    May 29, 2013 at 18:10
  • Ctrl-A is 1. How can I try this? My Gnome terminal does nothing when I press Ctrl-A.
    – robert
    Nov 3, 2017 at 8:44
  • I lied in my previous comment. In the decade since, I've assiduously marked up keyboard sequences with <kbd>.
    – Kaz
    Sep 6, 2023 at 6:10
4

To me, the simplest way to copy paste in the shell is:

Select the code you want and then past it by clicking the mouse-middle-key

3
  • 2
    As long as you have a middle mouse key.
    – jpierson
    Aug 29, 2015 at 11:35
  • 1
    @jpierson not that I am strongly recommending this, but you can write a small script that simply uses xdotool click 2 to emulate the third-button click for you. Then, in whatever window manager / desktop environment you are in, you can bind this script to a key - say mod i (for insert) or whatever keybindings you might have available (or whatever mod might mean - which really depends where you bind this)
    – dylnmc
    Oct 8, 2016 at 16:07
  • Whether that works or not has nothing to do with the shell, but what kind of terminal emulator you are using.. many X based terminals allow this mouse move. Aug 2, 2020 at 3:59
2

We can use insert keyboard button to do copy and paste(In old keyboards it can be missing)

Copy: CtrlInsert
Paste: CtrlShiftInsert

1
  • For pasting, it's normally just Shift+Insert
    – aff
    Sep 16, 2020 at 4:29
1

you can also use the middle button an a mouse if you are feeling lazy and select a command from either a text document, script or web or forum. once you've selected the intended command simply move to your terminal and click the middle button on the mouse. I use this method as I use puppy linux which doesnt seem to support the normal behaviour of right click and paste. it does in a file handler window, just not in a terminal window. dont know why but I'm quiet pleased I found out about the middle button method, very handy! ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .