次のコマンド
# top > /home/user/top_output.txt
「何も起こらなかった」をしばらく実行してから、を押しましたCtrl+C
。作成したファイルを確認したところ、内容が含まれていました。だから私 cat
はそれにコマンドを起動し、それは私にこの出力を与えました。
しかし、less
コマンドで同じことを試したところ、これがわかりました。
この投稿によると、の仕事はCat,less or More
、エンコーディングを翻訳せずにファイルの内容を表示することだけです。誰かがここで何が起こっているのか教えてもらえますか?
PS:私は現在Fedora19を使用しています
The escape sequences ESC [ ... m
are called ANSI Escape Sequences. top
sends them to your terminal to make it format output in color, bold, inverted text and so on. You never see these characters when running top
but you see the resulting format. You could think of it as looking at a webpage in a browser - you don't see the <html>...
formatting the content.
When dumping the output of top
into a file, you are saving the non-printable escape sequences with everything else. Think of it as saving view source
in your browser.
The default for less
is to escape terminal control characters, displaying them in a printable form.
The default for cat
is to pass them through to your terminal which interprets them and makes it look "normal".
Try 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.
cat -v /home/user/top_output.txt
印刷できない文字をエスケープするものと比較してください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加