5

Imaginary Situation: You’ve used mysqldump to create a backup of a mysql database. This database has columns that are blobs. That means your “text” dump files contains both strings and binary data (binary data stored as strings?)

If you cat this file to the screen

$ cat dump.mysql

you’ll often get unexpected results. The terminal will start beeping, and then the output finishes scrolling by you’ll often have garbage chacters entered on your terminal as through you’d typed them, and sometimes your prompts and anything you type will be garbage characters.

Why does this happen? Put another way, I think I’m looking for an overview of what’s actually happening when you store binary strings into a file, and when you cat those files, and when the results of the cat are reported to the terminal, and any other steps I’m missing.

4

3 回答 3

6

当您 cat 二进制文件时,您可能会无意中将控制字符发送到终端。

例如,如果终端应用程序想要发送哔哔声,它会向终端发送以下二进制文件:0x007(仅限 SYS V)。

颜色、光标位置等也是如此。

于 2010-04-12T18:58:48.793 回答
5

从这里开始:http: //www.faqs.org/docs/Linux-HOWTO/Keyboard-and-Console-HOWTO.html

特别是第 3 节(控制台通用性)和第 4 节(重置终端)。

它涵盖的内容比您所说的要多,但应该可以满足您的需求。

于 2010-04-12T18:58:04.130 回答
2

当您将二进制数据放到屏幕上时,终端会尝试将该二进制数据解释为 ASCII(或 UTF)。有些角色能够控制终端。例如,

echo "^[[0;31;40m" # The first ^[ comes from pressing Ctrl+v, Esc

将背景变为黑色,前景变为红色。用于reset使您的终端恢复正常。

于 2010-04-12T19:06:13.330 回答