This appears to be an easy concept, but I'm having difficulty finding out what is going on via Google:

I have a binary file generated by a C program, example_binary.

After using cat example_binary, the output looks like a typical output after running cat on a compressed file.

However, after cat has finished, letters and numbers remain on the command line. In this case, I see 1;2c.

$ cat example_binary
$ 1;2c

Why would there be leftover numbers and letters remaining on the command line? What does 1;2c mean?

  • You should not dump binary garbage to the terminal. Terminal emulators interpret some "binary" sequences starting with control characters (ascii 0-31 and 127) as COMMANDS, which may do a lot of funny and unexpected stuff. In that case, the terminal emulator probably responds with the cursor position or something similar, and the line editing features of your shell is only partially able to parse it. TL;DR; do not cat binary files to the terminal. – mosvy Apr 14 at 21:58
  • 1
    In this case, your binary file probably contains the \e[c sequence, which the terminal interprets as "Send Device Attributes" and to which it replies with \e[?1;2c ("VT100 with Advanced Video Option"). The readline library used by bash will eat up the \e[? part (probably assuming it's the start of the sequence generated by a function key like F10) and treat the rest as data entered by the user, and put it after the prompt. – mosvy Apr 14 at 22:08
  • You can simulate that by running cat in your terminal, then pressing the Esc, [, c and Enter keys. – mosvy Apr 14 at 22:35
  • 1
    It also somewhat repeats unix.stackexchange.com/q/578826/5132 . – JdeBP Apr 14 at 22:55
  • cat -vet is more civilised: it shows tabs as ^I, line ends as $, and nonprinting characters as controls (e.g. ^@ for NUL) or meta-chars (M-xx). No special characters come out as themselves. od (octal dump) is also useful. – Paul_Pedant Apr 15 at 16:05

Browse other questions tagged or ask your own question.