Showing results for 
Search instead for 
Did you mean: 

only show some processes

Honored Contributor

only show some processes


I have to display some interesting data for a menu

so I was checking the "top command"

so I decided that top commands display everything I need but I want o display only the top information not the rest I mean only the 4 first lines like I pasted on this thread..

top - 15:46:23 up 186 days, 5:14, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 114 total, 1 running, 113 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.5%us, 0.2%sy, 0.0%ni, 98.2%id, 1.0%wa, 0.0%hi, 0.2%si, 0.0%st
Mem: 2075500k total, 1741508k used, 333992k free, 339992k buffers
Swap: 3047416k total, 64k used, 3047352k free, 1140164k cached

how can I do that? I want to only display those values and I need it to be updated

thanks a lot
Didn't your momma teach you to say thanks!
Jared Middleton
Frequent Advisor

Re: only show some processes

Actually, your example shows 5 lines, not 4.

How about:
top -b | head -5
Honored Contributor

Re: only show some processes

thanks someone else provided me these 2

1. it has the option to press q to exit
VAR=x ; while [ "${VAR}" != 'q' ] ; do top | head -4 ; read -sn 1 -t 2 VAR ; done

2. no q option to exit
watch -n 2 'top -b -n1| head -n 4'

the point for both is they don't really update the CPU options

anyway to fix that?
Didn't your momma teach you to say thanks!
Goran Koruga
Honored Contributor

Re: only show some processes

You want only the upper lines?

LINES=5 top