How to capture the output of a top command in a file in linux?

后端 未结 10 933
梦如初夏
梦如初夏 2020-12-24 06:14

I want to write the output of a specific \'top\' command to a file. I did some googling and find out that it can be done by using the following command.

top         


        
10条回答
  •  醉梦人生
    2020-12-24 06:42

    I had the exact same problem...

    here was my line:

    top -b -u myUser | grep -v Prog.sh | grep Prog > myFile.txt
    

    It would create myFile.txt but it would be empty when I Ctrl+C'd it. So after I kicked off my top command, then I started a SECOND top process. When I found the first top's PID (took some trial and error), and I killed it thru the second top, the first top wrote to the file as expected.

    Hope that helps!

提交回复
热议问题