74

Occasionally, I need to check resources on several machines throughout our data centres for consolidation recommendations. I prefer htop primarily because of the interactive feel and the display.

Is there a way to customise some settings to my setup for htop? For example, one thing I'd always like to have shown is the average CPU load.

Important note: Setting this on specific boxes isn't feasible - I'm looking for a way to set this dynamically every time I SSH into the box.

Is this possible at all?

0

7 Answers 7

81

htop has a setup screen, accessed via F2, that allows you to customize the top part of the display, including adding or removing a "Load average" field and setting it's style (text, bar, etc.).

These seem to be auto saved in $HOME/.config/htop/htoprc, which warns:

# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.

I.e., edit that at your own risk. However, you should be able to transfer it from one system to another (version differences might occasionally cause a bit of an issue).

You could also set up a configuration, quit, and then copy the file, so that you could maintain a set of different configurations by swapping/symlinking whichever one with htoprc.

3
  • Thanks. I just blindly copied htop config from a good looking server to ugly looking server. It made the ugly looking server look great! Oct 11, 2017 at 15:42
  • 2
    Also, note that if you lose permission to your htoprc, such as by accidentally touching it as root/sudo, htop will be unable to update this file and silently fail to save your changes.
    – Cerin
    Dec 19, 2017 at 0:50
  • @Cerin This is an important point - I think it would be great if the author would add it to their answer.
    – Amr Bekhit
    Dec 5, 2018 at 6:54
71

The easiest way is to use the setup in the program and then save and exit the program with F10, not with CTRL+C. Next time you can close the program the way you like.

4
  • 26
    TL;DR: Exit with F10, not CTRL-C. Aug 15, 2016 at 19:14
  • 1
    At least on linux, quitting with 'Q' also does NOT save your changes... ;(
    – ljwobker
    Dec 29, 2017 at 0:06
  • 3
    To unbind F10 from opening the terminal window's File menu in Ubuntu, in a terminal window: Edit > Preferences > General: uncheck 'Enable the menu accelerator key (F10 by default)' Nov 29, 2018 at 16:20
  • If F10 is bound to a terminal emulator shortcut, you can also use the mouse to click "Exit" on the bottom.
    – pcworld
    Apr 30, 2020 at 15:59
8

Reset the settings in the config file

This are the default settings for htop on a Ubuntu 18.04 system. Replace the content of the file $HOME/.config/htop/htoprc and you should be fine. Make a backup first.

# Beware! This file is rewritten by htop when settings are changed in the interface.
# # The parser is also very primitive, and not human-friendly.
fields=0 48 17 18 38 39 40 2 46 47 49 1 
sort_key=1
sort_direction=1
hide_threads=0
hide_kernel_threads=1
hide_userland_threads=0
shadow_other_users=0
show_thread_names=0
show_program_path=1
highlight_base_name=0
highlight_megabytes=1
highlight_threads=1
tree_view=0
header_margin=1
detailed_cpu_time=0
cpu_count_from_zero=0
update_process_names=0
account_guest_in_cpu_meter=0
color_scheme=0
delay=15
left_meters=LeftCPUs Memory Swap 
left_meter_modes=1 1 1 
right_meters=RightCPUs Tasks LoadAverage Uptime 
right_meter_modes=1 2 2 2 
3
  • Thanks, I was looking for these and didn't find mention of them in man htop. Where did you find these? May 10, 2022 at 3:04
  • UPDATE: I see now, in the $HOME/.config/htop/htoprc. They weren't in $HOME/.htoprc where I was looking. May 10, 2022 at 3:09
  • Thanks sir. I really need this a thousands years ago :( hehe :)
    – haidarvm
    Jan 30 at 23:40
4

For any Mac users, the htop config file may be located in either of two places:

  1. under a config subdirectory in home: $HOME/.config/htop/htoprc
  2. right at the home directory: $HOME/.htoprc,

The first option (under .config/htop/ is preferred -- as mentioned in htop's manpage as well as my own experiments.

On a 2014 MacBook Pro, the second location was used, while on a 2017 MacBook Pro the first location is used, though in both cases Homebrew was used to install htop, and both laptops are (as of 10/29/17) running macOS 10.12.6. (thanks to @iconoclast for pointing out the discrepancy)

In either case, the same config file format can be used, and in both cases, it's recommended you change any settings via htop's own setup instead of directly editing the config file, as it's automatically generated.

0
1

Just had the same problem, but quitting htop with F10 didn't help save the settings. It appeared that this user's ~/.config belonged to root.

To check this:

$user@host:~$ ls -hal ~ |grep config

drwx------  4 root root 4.0K Mar 25  2015 .config

If it lists any user other than you, you should chown the directory to make your htop able to write in it:

sudo chown user:mygroup ~/.config

(replace "user" and "mygroup" with your username and group)

There is a "softer" way when you just give yourself permission to write but do not change the owner. But I cannot imagine why one should not own their ~/.config. Please tell me if I'm wrong.

1
  • Also encountered this. I know I have run sudo htop at some point, which likely wound up saving the config file with root's user and group.
    – user86616
    Feb 27, 2017 at 16:53
1

Okay, though this post may be old, I had the same issue.

Use the setup htop provides, which the asker had already done, but the settings were not being saved upon SSH, which is likely because there is no htoprc. Upon creating one, htop will then use it to save and load settings, rather than defaulting to its stock setup.

After reading @goldilocks and @TCAllen07 response, I sought to check if I even had a htoprc to begin with. It was not present. So, even though I owned my config directory from install, if I changed the setup, the settings would be lost. To solve it, I simply created the htoprc file in it's directory using touch .config/htop/htoprc, then I edited the settings from within htop interface and used cat .config/htop/htoprc to see that the changes were saved.

OS: Fedora 25 LK: 4.9.9-200.fc25.x86_64

1
  • @Fox the answer is in fact provided. It's too use the setup htop provides, which the asked had already done, but the settings were not being saved upon SSH, which is likely because there is no htoprc. Upon creating one, htop will then use it to save and load settings, rather than defaulting to its stock setup. Feb 15, 2017 at 12:19
1

You could also use a folder, shared among all your machines. Let's say that /media/shared is mounted equally on all machines. You can set it as your $HOME for htop, then it will save and load its configuration there.

HOME=/media/shared htop

This will start htop with a clean configuragion. Setup and close htop with F10 (or q). You could also copy your current configuration:

cp ~/.config/htop/htoprc /media/shared/.config/htop/htoprc

Now launch htop on your other machine(s):

HOME=/media/shared htop

It should be configured as you did on your previous machine. :)

1
  • 2
    Don't be "smart" and set $HOME globally in your shell session by doing export HOME=/media/shared. This may cause headaches. :-) Aug 1, 2017 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .