Adi*_*rla 8 less terminal escape-characters cat
我执行了以下命令
# top > /home/user/top_output.txt
什么也没发生,然后我按下了Ctrl+C
。当我检查创建的文件时,里面有内容。所以我向 cat
它发射了命令,它给了我这个输出。
但是当我用less
命令尝试同样的事情时,我得到了这个。
根据this post的工作Cat,less or More
只是显示文件的内容而不是翻译编码。有人可以告诉我这里发生了什么吗?
PS:我目前使用的是 Fedora 19
gre*_*eke 14
转义序列ESC [ ... m
称为ANSI 转义序列。top
将它们发送到您的终端,使其以彩色、粗体、倒排文本等格式输出。运行时您永远不会看到这些字符,top
但您会看到结果格式。您可以将其视为在浏览器中查看网页 - 您看不到<html>...
内容的格式。
将 的输出转储top
到文件中时,您将与其他所有内容一起保存不可打印的转义序列。将其视为保存view source
在浏览器中。
默认为less
转义终端控制字符,以可打印的形式显示它们。
默认cat
是将它们传递到您的终端,终端会解释它们并使其看起来“正常”。
尝试 less -r /home/user/top_output.txt
Run Code Online (Sandbox Code Playgroud)$ man less ... -r or --raw-control-chars Causes "raw" control characters to be displayed. The default is to display control characters using the caret notation; for example, a control-A (octal 001) is displayed as "^A". Warning: when the -r option is used, less cannot keep track of the actual appearance of the screen (since this depends on how the screen responds to each type of control character). Thus, various display problems may result, such as long lines being split in the wrong place.
比较cat -v /home/user/top_output.txt
哪个将转义不可打印的字符。