How do you use top with just showing the CMD name?

I have used top with just showing the running process that I want; for example:

$ top -p 19745

And if I want more than one PID, I would use:

$ top -p 19745 -p 19746 -p 19747

I have Googled it, but they don't say how you can do it, even when I try looking at the help in top it still doesn't show you.

Is there a way you can filter by the CMD name only?

There are certain files that I am running through Apache2, and I want to monitor them only.



I see this in the man top page:

x: Command  --  Command line or Program name
      Display the command line used to start a task or the name of the associated
      program.   You toggle between command line and name with 'c', which is both
      a command-line option and an interactive command.

      When you've chosen to display command lines, processes  without  a  command
      line  (like  kernel  threads)  will  be shown with only the program name in
      parentheses, as in this example:
            ( mdrecoveryd )

      Either form of display is subject to potential truncation if it's too  long
      to fit in this field's current width.  That width depends upon other fields
      selected, their order and the current screen width.

      Note: The 'Command' field/column is unique, in that it is not  fixed-width.
      When  displayed,  this  column will be allocated all remaining screen width
      (up to the maximum 512 characters) to provide for the potential  growth  of
      program names into command lines.

Will that do anything for me?


If your top supports filtering, start top then type the following interactive command:


The field name, COMMAND, must be all uppercase.

From the man page:

5e. FILTERING in a Window
   You can use the 'Other Filter' feature to establish selection cri‐
   teria which will then determine which tasks are shown in the ´cur‐
   rent´ window.

   Establishing a filter requires: 1) a field name; 2)  an  operator;
   and  3) a selection value, as a minimum.

   Filter Basics
      .  field names are case sensitive and spelled as in the header
      .  selection values need not comprise the full displayed field
      .  separate unique filters are maintained for each task window

Keyboard Summary
     o  :Other-Filter (lower case)
         You will be prompted to establish a filter that ignores case
         when matching.

     O  :Other-Filter (upper case)
         You will be prompted to establish a case sensitive filter.
  • Should I use this command line: top oCOMMAND=afile? I tried that and got: top: unknown argument 'o' – Kevdog777 Jul 30 '14 at 15:36
  • The o command is an interactive command only, as far as I can tell. Start top first, then type it. – Mark Plotnick Jul 30 '14 at 15:37
  • Oops, I moved the X: COMMAND to the top of the filters list. It is now in the front of the list. But I can't filter it by only that one filename: afile – Kevdog777 Jul 30 '14 at 15:42
  • I have used top -i and have all the running processes, which is sufficient for me, as I have this machine on VirtualBox. – Kevdog777 Jul 30 '14 at 15:56

I believe you could do something like below as suggested here.

top -p `pgrep -d ',' "apache2"`

I believe the comma delimiter is not needed in this case as we have only one process.

top -p `pgrep "apache2"`
  • Sorry, I edited my post, saying: "There is a certain file that I am running through Apache2, and I want to monitor it only." - I can sort them alphabetically by pressing c, but that doesn't really help... Well it does for me, as the filename starts with "A" – Kevdog777 Jul 30 '14 at 14:41
  • @Kevdog777, please see the updates. – Ramesh Jul 30 '14 at 14:42
  • Oh wait, it disappears when it refreshes itself. – Kevdog777 Jul 30 '14 at 14:45
  • @Kevdog777, I believe the comma delimiter is not needed in pgrep. Can you try the updated command? – Ramesh Jul 30 '14 at 14:56
  • I am getting this: top: unknown argument '1' – Kevdog777 Jul 30 '14 at 14:58

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.