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

后端 未结 10 937
梦如初夏
梦如初夏 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:30

    As pointed out by @Thor in a comment, you just need to ensure that grep is not buffering arbitrarily but per-line with the --line-buffered option:

    top -bn 10 | grep 'init' --line-buffered | tee top-output.txt
    

    Without grep-ing, redirecting the output of top to a file works just fine, interrupt included.

提交回复
热议问题