I'm on Ubuntu 18.04. I'm already aware that I can start htop, and then hit F4 for filter, then type or paste a process name search query (say, gphoto2 for looking for gvfs-gphoto2-volume-monitor.service), and then htop filters the shown processes: if there is no such process, it shows nothing, if it starts later, htop shows it then.

Now, I would like to start htop with filtering already from the command line, say:

htop --filter="gphoto2"

... and get the exact same behavior as if hitting F4 and typing in the terminal UI. This would be useful if integrating the command into, say, a tmux session.

I browsed through man htop, but unfortunately I cannot see such command line/option. Closest I've seen is -p, which as noted in how to show only processes *not* matching a filter? :

Something like

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

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

So, is there a way to set up process name filtering on the command line at startup, such that it takes account for newly killed or spawned processes (as if hitting F4 in htops terminal UI) - for htop, or top, or any other similar program?

  • 1
    A very useful feature indeed! Have you managed to find a solution? – Slava Fomin II Jun 26 '19 at 15:22

I went looking for this option, too, and it doesn't exist. I settled for (using your search-term):

\# ps -aux |grep "[0-9] gphoto2"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.