30

Sometimes, when copy-pasting text from the output of commands, I'll accidently use Ctrl+c instead of Ctrl+Shift+c.

So the command-line interprets it as ^C...

Why is this? Why does the command-line interpret control input as ^?

4 Answers 4

42

It does not actually insert the character sequence "^C". This is only a representation for unprintable ASCII control characters, such as:

  • ^C → ETX (End of text, sends a kill signal), ASCII 0x03
  • ^D → EOT (End of transmission, terminates input), ASCII 0x04
  • ^H → BS (Backspace, \b), ASCII 0x08
  • ^J → LF (Line feed, \n), ASCII 0x0A
  • ^L → FF (Form feed, new page, clears the terminal), ASCII 0x0C
  • ^M → CR (Carriage return, \r), ASCII 0x0D

This is only a small extract of possible ASCII control characters that can be inserted using the keyboard; you can find a full list here.

I think the most important ones to remember are Ctrl+C, Ctrl+D and Ctrl+L.

1
  • The use of the caret ^ as a symbol for "control" dates back to pre-graphic times when terminals were text-only, and I believe even before then when we had cards and paper, no terminals. I'd love to know why the caret was chosen as the symbol. Dec 8, 2015 at 12:21
8

Because CTRL+KEY combos are interpreted by the terminal as non-printable ASCII characters, and being those non-printable you need a way to represent them.

The convention, stemming from VT terminals with ANSI support, is to represent the CTRL+KEY combo representing CTRL with a caret (^) and KEY with KEY.

5

When copying and pasting to/from a terminal, it is best practise to use the short cuts Ctrl+Insert and Shift+Insert respectively.

These are the more traditional short cuts for terminal use, though you'll note that in an X graphical environment Ctrl+Insert and Shift+Insert are tied to the same Ctrl+C and Ctrl + V.

In most terminals Ctrl+C (represented by ^C) are used to halt the execution of a process, hence pasting with that short cut won't work.

For quick copying and pasting, you can utilize X's primary buffer by highlighting whatever text you want to copy, and then middle-clicking where you want to paste it. No keyboard required.

2
  • 2
    Sorry, but you misunderstood the question. OP wanted to know why the string ^C or similar ones appear when pressing CTRL+C (or CTRL+ another letter). It's not about how to correctly copy and paste stuff in the terminal, for which your answer would be great.
    – Byte Commander
    Dec 1, 2015 at 17:18
  • @ByteCommander, right you are! my apologies, I'll leave my answer as is however, as it seems the question has been properly answered already :) Someone might stumble across this and find what I wrote useful. Dec 2, 2015 at 3:26
-2

You should be using Ctrl+C and not Shift+Ctrl+C, because on the command line, they do the same thing (and Ctrl+C is easier than Shift+Ctrl+C). That might not be true in certain graphical environments where the GUI captures some keystrokes and does something special, but if the keystrokes are truly sent to the command line, then there is no difference. This is why pressing Ctrl+C may show ^C as a capital C, instead of a lowercase C. The command line makes no distinction on which one you pressed (and uppercase was presumably judged to be easier to read). This is true for letters; for other characters, the Shift may have an effect.)

Pressing Ctrl-C sends the ASCII code that is 64 below the uppercase letter's position in the ASCII table (and 96 less than the lowercase letter's position in the ASCII table). So pressing Ctrl-c (lowercase) sends ASCII code 3 (which is 64 less than capital C's ASCII code of 67). In many environments, you can hold Alt and then press 3 on the numpad (and then release the 3 key, and then release the Alt key) and you may get the same effect.

Regarding ^C, the ^ is just a well-known shorthand for the "Ctrl" key. Similarly, M- is a shorthand for the "Alt" key. Err, yeah. M stands for the word "Meta", which can be entered by holding Alt and pressing whatever comes next, or sometimes by pressing Esc (and releasing Esc) and then pressing whatever comes next. Wikipedia's article on "Control Key": "Notation" section describes this as "Traditional notation". This is also known as Caret Notation (Wikipedia's article on Caret notation, Unix StackExchange: ryvnf's question about Caret Notation).

Regarding the last question, the command shell is not "interpreting" anything to be a caret. In other words, the shell is not reading anything, and believing that it is a caret. What is happening is that the shell is using the well-known caret notation for output. As another example, you can see the well-known pager, "less", use caret notation by running: dd if=/dev/zero bs=64 count=1 | less

(The "nano" text editor also uses caret notation in its online help, including the full screens of online help shown after pressing ^G, a.k.a. Ctrl-g.)

1
  • 4
    DevRobot is specifically asking about using Ctrl-C (or rather Shift-Ctrl-C) in the context of copy and paste, which implies a GUI terminal. You're not necessarily incorrect, but you're explanation is definitely confusing for someone coming from a GUI-user perspective.
    – R.M.
    Dec 1, 2015 at 23:32

You must log in to answer this question.

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