How do I change the output line length from the "top" linux command running in batch mode
Posted
by Tom
on Server Fault
See other posts from Server Fault
or by Tom
Published on 2010-04-30T09:16:28Z
Indexed on
2010/04/30
9:17 UTC
Read the original article
Hit count: 200
The following command is useful to capture the current processes that are taking up the most CPU in a file:
top -c -b -n 1 > top.log
The -c
flag is particularly useful because it gives you the command line arguments of each process rather than just the process name.
The problem is that each line of output is truncated to fit on the current terminal window. This is ok if you can have a wide terminal because you have a lot of the output but if your terminal is only 165 characters wide, you only get 165 characters of information per process and it is often not enough characters to show the full process command. This is a particular problem when the command is executed without a terminal, for example if you do it via a cron job.
Does anyone know how to stop top
truncating data or force top
to display a certain number of characters per line?
This is not urgent because there is an alternative method of getting the top 10 CPU using processes:
ps -eo pcpu,pmem,user,args | sort -r -k1 | head -n 10
© Server Fault or respective owner