问题描述
我尝试将 htop
传送到文本文件(例如 htop > text.txt
),但它让我的文本因格式化字符串而出现乱码(见下文).有没有办法获得更好的、人类可读的输出?
I've tried piping htop
to a text file (e.g. htop > text.txt
) but it gives me text garbled by formatting strings (see below). Is there a way to get nicer, human readable output?
^[7^[[?47h^[[1;30r^[[m^[[4l^[[?1h^[=^[[m^[[?1000h^[[m^[[m^[[H^[[2J^[[1B ^[[36m1 ^[[m^[[1m[^[[m^[[32m||||||||||^[[31m||||||||||^[[30m^[[1m
22.2%^[[m]^[[m ^[[36mTasks: ^[[1m159^[[m^[[36m total, ^[[32m^[[1m5^[[m^[[36m running^[[3;3H2 ^[[m^[[1m[^[[30m
0.0%^[[m]^[[m ^[[36mLoad average: ^[[30m^[[1m1.11 ^[[m^[[m1.28 ^[[1m1.31 ^[[4;3H^[[m^[[36m3 ^[[m^[[1m[^[[m^[[32m||||||||||^[[30m^[[1m
11.1%^[[m]^[[m ^[[36mUptime: ^[[1m9 days, 22:04:51^[[5;3H^[[m^[[36m4 ^[[m^[[1m[^[[30m 0.0
%^[[m]^[[6;3H^[[m^[[36m5 ^[[m^[[1m[^[[m^[[31m||||||||||^[[30m^[[1m 11.1%^[[m]^[[7;3H^[[m^[[36m6 ^[[m^[[1m[^[[30m
推荐答案
htop author here.
htop author here.
不,没有好"的方法可以将 htop 的输出通过管道传输到文件中.它是一个交互式应用程序,并使用终端重绘例程来生成其界面(因此,将其通过管道传递与将 vim 管道传递到文本文件一样有意义——您将获得类似的结果).
No, there's no "nice" way to get the output of htop piped into a file. It is an interactive application and uses terminal redraw routines to produce its interface (therefore, piping it makes as much sense as, for example, piping vim into a text file -- you'll get similar results).
要以文本格式获取有关您的进程的信息,请使用ps".例如,ps auxf >file.txt
为您提供了许多易于解析的信息(或 ps aux
如果您不希望树格式 - 请参阅 man ps
了解更多选项).
To get the information about your processes in a text format, use "ps". For example, ps auxf > file.txt
gives you lots of easy to parse information (or ps aux
if you do not wish tree-formatting -- see man ps
for more options).
这篇关于htop 输出到人类可读文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!