Search code examples
filedelay

top command run infinite time with delay specification output to a file


There is this "top" command in linux which is used to measure various real time CPU metrics.

Can someone explain how to use that command so that it gets updated every 1 second and does it for infinite time (or say till when I desire to run it). Also if it could output the values in a text file.

So I tried:

top -n -d 1 -b >> output.txt

But how should I specify the parameter values for n. I don't want to put some random values for -n parameter say 10000 etc.


Solution

  • 1.) explain update every one second: you did it yourself: '-d 1'

    2.) explain output to a text file: you did it youself: '>> output.txt' This will append (if necessary create new) to the file 'output.txt'.

    3.) if you want to run it for ever, just leave out the parameter '-n '.

    But NOTE: If it runs 'forever': Think of the file system space your output file will eat up!!!