views:

611

answers:

9

If I do something like:

$ cat /bin/ls

into my terminal, I understand why I see a bunch of binary data, representing the ls executable. But afterwards, when I get my prompt back, my own keystrokes look crazy. I type "a" and I get a weird diagonal line. I type "b" and I get a degree symbol.

Why does this happen?

+1  A: 

You're getting some control characters piped into the shell that are telling the shell to alter its behavior and print things differently.

Steve g
A: 

Special control characters can affect the display of some terminal programs.

However all is not lost. Sometimes if you enter "stty sane", the terminal recovers.

paxdiablo
+17  A: 

Because somewhere in your binary data were some control sequences that your terminal interpreted as requests to, for example, change the character set used to draw. You can restore everything to normal like so:

reset
Nick Johnson
A: 

VT100 is pretty much the standard command set used for terminal windows, but there are a lot of extensions. Some control character set used, keyboard mapping, etc.

When you send a lot of binary characters to such a terminal, a lot of settings change. Some terminals have options to 'clear' the settings back to default, but in general they simply weren't made for binary data.

VT100 and its successors are what allow Linux to print in color text (such as colored ls listings) in a simple terminal program.

Adam Davis
A: 

If you really must dump binary data to your terminal, you'd have much better luck if you pipe it to a pager like less, which will display it in a slightly more readable format. (You may also be interested in strings and od, both can be useful if you're fiddling around with binary files.)

Dan
This does not answer the "why", so perhaps it should be a comment to the question.
ΤΖΩΤΖΙΟΥ
+1  A: 

The terminal will try to interpret the binary data thrown at it as control codes, and garble itself up in the process, so you need to sanitize your tty.

Run:

stty sane

And things should be back to normal. Even if the command looks garbled as you type it, the actual characters are being stored correctly, and when you press return the command will be invoked.

You can find more information about the stty command here.

dsm
A: 

SPECIAL TUESDAY BONUS ANSWER

This does not answer the question! It is a BONUS ANSWER!

If you want to have a look at the contents of /bin/ls, try this:

$ cat /bin/ls | od -a
jfm3
Mrs. Carlson of Chester, AL downvoted the BONUS ANSWER, and caught a case of the gout and the shingles at the same time. The next day, she changed to upvote the BONUS ANSWER. Not only was her Gouth, Shingles, and Whooping cough cured, but her car runs better than ever now.
jfm3
NB: an answer that is not an answer to the question, should be a comment to the question.
ΤΖΩΤΖΙΟΥ
+3  A: 

This link has the best answer I've seen so far.

raldi
A: 

Just do a copy-paste:

echo -e '\017'

to your bash and characters will return to normal. If you don't run bash, try the following keystrokes:

<Ctrl-V><Ctrl-O><Enter>

and hopefully your terminal's status will return to normal when it complains that it can't find either a or a command to run.

, or character 14, when sent to your terminal, it orders it to switch to a special graphics mode, where letters and numbers are replaced with symbols. , or character 15, restores things back to normal.

ΤΖΩΤΖΙΟΥ