I need to monitor both CPU usage and a specific log file and switch between them regularly.
Is there a better way than Ctrl+C, up-arrow, up-arrow, Enter? (And optionally also re-configuring top each time to sort by mem)
Ideally, with just one key stroke.
I know I can workaround with two terminal windows and Alt-Tab, but I have to also do a lot of other work and having to juggle that extra window is inconvenient.
One way to achieve this is by using infinite while loop.
Code:
Explanation:
top -n 5- Allows you to specify after how many refreshes (Default refresh time is 3 seconds.) should top command quit. (The top command will exit after 5 refreshes in this example)top -o %MEM- To sort by memory usage.timeout 5- timeout exits command after given interval. (5 seconds in this example).You can change the time interval of
topandtimeoutas per your requirement.To break out of the loop you can use
Ctrl+C.Hope this helps!