16

I'm using htop to interactively monitor my processes.

However, sometimes a few processes get "in the way" and I would like to filter them out.

Unfortunately, it seems that htop's built in filter (e.g. F4) only allows me to define a positive filter (only matches will be shown), and not negative filters (all but matches are shown).

Finally, I haven't found any documentation about the actual syntax of the search-string (regexes don't seem to work).

umläute
  • 6,300
  • 1
  • 24
  • 48
  • AFAIK is not possible. Any good reason to not use top? You can do it easily with it. – sebelk Sep 24 '15 at 13:47
  • 1
    FWIW htop filtering should gain regex filtering soon, there is a complete though still unmerged pull-request on GitHub. https://github.com/hishamhm/htop/pull/428 – Richard Michael Jan 09 '17 at 20:53
  • 1
    The project was moved to https://github.com/htop-dev/htop but the MR seems to me forgotten. – Matthias B Sep 24 '20 at 11:45

2 Answers2

6

I don't know if it's doable with htop but if using another top implementation is an option, with the top implementation in procps on Linux (generally the default implementation there), from within top, you can

  1. enter o (or O for case sensitive matching)
  2. enter !COMMAND=notwanted (or !USER=unwanted)

to filter out the processes whose name (or command line after pressing c) contains notwanted (or whose username contains unwanted). Enter = to remove all the filters.

You can filter on any of the fields you want, but only when they are displayed. For instance, to exclude kernel tasks, you can ask for the CODE column to be displayed (with f) and then filter on CODE>0 (with o).

Note that the default interface of that top implementation may look cruder than that of htop, but it has actually quite a lot more features (and you can configure it with colour and extra information if need be).

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
4

Do not know of a direct way with htop

However you might be able to use the negating abilities of pgrep and feed a pid list to htop

Something like

htop -p "$(pgrep -vfd, 'java|python')"

This has the obvious disadvantage of not accounting for processes that start after htop starts running

iruvar
  • 16,515
  • 8
  • 49
  • 81
  • 2
    good idea, but what i really want to do is filter out "garbage" processes when I see them; so your solution is not really "interactive" in that sense... – umläute Sep 24 '15 at 13:30