I want to show all processes whose command line includes .*git.*
using top
.
I've considered the following command: top -p $(pgrep -d',' -f '.*git.*')
However, the above command has several caveats:
- Only processes that exist while
top
is executed will be included intop
's output (new.*git.*
s are not included). man top
says that at most 20 processes may be specified using the-p
flag, which may not be sufficient.
How can I show a dynamically top
-like view of current .*git.*
processes in the terminal?
Best Answer
You can do this in
top
using “filtering in a window”: starttop
, then press O, and enterThis will filter processes, matching the
COMMAND
column and keeping only processes whose visible value in that column containsgit
.When filtering on the
COMMAND
column, the filter applies to the currently-displayed value — either the name of the running program, or its full command line. This can be toggled by pressing c, or with the-c
argument; the state is remembered betweentop
invocations. Note that the filter applies only to the visible portion of the field; this can be a significant gotcha when filtering on theCOMMAND
column, if it isn’t fully visible or if it isn’t wide enough to include the relevant part of the command line. See theCOMMAND
field description inman top
for details.Filters are cumulative and can be cleared by pressing =. See section 5e of
man top
for details.As far as I’m aware there’s no equivalent command-line option.