Ubuntu – How to save htop output to file

htop

How can I save the output of htop to a file? With top, I can run

top -b -n1 > top.txt

where -b specifies batch mode and -n specifies the number of iterations.

But the man page of htop doesn't offer such a possibility.

Is taking a screenshot the only way?

Best Answer

Ron provided a link to htop output to human readable file and a quote from the top-voted answer by the developer of htop.

However, a little further down on the same page, there's a solution which uses ANSI to HTML conversion. Briefly, install aha from the software center and then run:

echo q | htop | aha --black --line-fix > htop.html

Here's what the first few lines look like:

  1  [|||||||||||||||||||||||||||||||||                                    42.9%]     Tasks: 73, 251 thr; 1 running
  2  [||||||                                                                7.1%]     Load average: 0.28 0.32 0.32 
  Mem[||||||||||||||||||||||||||||||||||                              581/3916MB]     Uptime: 03:09:25
  Swp[                                                                  0/4056MB]
  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command          
 9785 dkb        20   0 31544  2464  1312 R 22.2  0.1  0:00.09 htop             
 3503 dkb        20   0 1065M 59684 16344 S  7.4  1.5  6:25.43 mpv --profile=pseudo-gui -- file:///home/dkb/Downloads/ONX
    1 root       20   0 33760  3088  1488 S  0.0  0.1  0:01.62 /sbin/init        
  276 root       20   0 19472   652   460 S  0.0  0.0  0:00.19 upstart-udev-bridge --daemon
  281 root       20   0 52592  2640  1016 S  0.0  0.1  0:00.76 /lib/systemd/systemd-udevd --daemon
  577 root       20   0 15256   632   388 S  0.0  0.0  0:00.05 upstart-socket-bridge --daemon
  662 root       20   0 15272   416   200 S  0.0  0.0  0:00.04 upstart-file-bridge --daemon
  677 syslog     20   0  249M  1304   836 S  0.0  0.0  0:00.01 rsyslogd          
  678 syslog     20   0  249M  1304   836 S  0.0  0.0  0:00.00 rsyslogd          
  679 syslog     20   0  249M  1304   836 S  0.0  0.0  0:00.02 rsyslogd          
  675 syslog     20   0  249M  1304   836 S  0.0  0.0  0:00.04 rsyslogd          
  680 messagebu  20   0 39860  1968  1044 S  0.0  0.0  0:00.52 dbus-daemon --system --fork
Related Question