29

Is there any switch to tell top command in order to one time scan the system and do not monitor it all time?

Dan
  • 6,753
  • 5
  • 26
  • 43
Mohammad Reza Rezwani
  • 10,286
  • 36
  • 92
  • 128
  • 8
    if you want to know something about a command, first read the man page of corresponding command (man command). – Avinash Raj Jun 17 '14 at 11:39

2 Answers2

38

The -n switch is what you search:

user@host:~$ top -n 1

See the manpage

   -n : Number of iterations limit as:  -n number
        Specifies the maximum number of iterations, or frames, top should produce before ending.

If you want to stop top command just press q.

Notice: If you tend to use top in a script, I need to say top is not meant for scripts, use ps instead.

Pandya
  • 35,771
  • 44
  • 128
  • 188
chaos
  • 27,506
  • 12
  • 74
  • 77
12

notice that if you would like to keep "top" command for a script, you could use -b option ("-b" option means "batch mode operation"), this option allows you to redirect the output into a file.

Examples:

  • top one shoot batch mode : top -bn 1 2>&1 1> /tmp/topN
  • top sorted by memory usage one shoot batch mode : top -ban 1 2>&1 1> /tmp/topAN
boly38
  • 223