Home > Back-end >  How to show the top 4 processes to another file using Bash commands?
How to show the top 4 processes to another file using Bash commands?

Time:03-31

processes I'd like to get top 4 processes to another file, instead of all it!

I know how to transfer all the data from "top" command to a new file, but again, just one top 4 instead all of it. I think it has something to do with grep command...

CodePudding user response:

You can use awk to limit the lines to be captured to the top 4 lines then output to a new file.

$ top -n1 | awk 'NR >= 7 && NR <= 11' > new_file

CodePudding user response:

Try this:

    top | head  -17 | tail -10 > file

Since top output (in my pc) has 7 lines prior to the actual process list you select first 17 lines head -17 Then keep those last lines 10 containing actual data related to processes: tail -10

Regards

  • Related