Cat 和 Less 给出不同的输出

Adi*_*rla 8 less terminal escape-characters cat

我执行了以下命令

# top > /home/user/top_output.txt

什么也没发生,然后我按下了Ctrl+C。当我检查创建的文件时,里面有内容。所以我向 cat它发射了命令,它给了我这个输出。
文本文件的 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

   $ 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.
Run Code Online (Sandbox Code Playgroud)

比较cat -v /home/user/top_output.txt哪个将转义不可打印的字符。