Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htop output to human readable file

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           \ 
like image 377
DilithiumMatrix Avatar asked Jul 08 '13 19:07

DilithiumMatrix


People also ask

How do I copy from htop?

Run your processes, switch to htop window and carefully do Ctrl + Shift + A to select everything, then release A and hit C (without releasing Ctrl + Shift). It might take some time to be able to do it (some of the times you might kill htop accidentally).

What is the difference between htop and top?

“Htop is a free (GPL) ncurses-based process viewer for Linux. It is similar to top, but allows you to scroll vertically and horizontally, so you can see all the processes running on the system, along with their full command lines.”


1 Answers

htop author here.

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).

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).

like image 116
Hisham H M Avatar answered Nov 13 '22 17:11

Hisham H M