The "command" column gets truncated by the width of the screen and I am unable to see the last part of it.
I have tried to reduce the font size so I can see a longer part of the command line but it still won't do.
The command field is by default truncated automatically for better reading.
You need to run
top -c
to show full command then depending on your console window's capabilities you would be able to scroll to right and see full command.
top -bcn1 -w512
The elegant solution is to use the option -w [number]
. According to the man page, the maximum width is 512 characters, so you will need a different solution for anything exceeding that. Presumably you also want to see the full length of the commands, so use the -c
option. We need to run top
in "batch mode", -b
, or it will continue to cut off the commands with a "+". Batch mode kind of makes a mess because it prints out all the jobs every second, so we can use the -n1
option to print out just one instance.
See the man top page for more information.
top
.
Feb 26, 2018 at 23:58
man top
says -c :Command-line/Program-name toggle ... Starts top with the last remembered 'c' state reversed
. which means -c
would only display full commands every 2nd execution.
-c
simply reversing the last state, though it is the same on my machine (rhel8). I find it a bit bizarre that a flag for a very common command like top is not 'absolute', and depends on the previous run. I fail to see why they made this choice.
As Daniel Arndt said, you can also use htop instead of top. It's available on all distro nowadays, and it provides better numbers (especially for memory usage)
It is also far easier to use and nicer to see, even if it's limited to terminal's colors. You can scroll to the right in order to see the full command, for instance, or you can kill a process with a simple F9. You can also see full tree with 't' key.
htop
is a nice program indeed but the question was about top's output. Please remain on topic.
This is hacky, but you can modify the behavior by adjusting the $COLUMNS and $LINES shell variables before launching top:
export COLUMNS=$((COLUMNS*2))
export LINES=$((LINES/2))
top
This will convince the shell that you have twice as many columns to write to (and half as many rows, to offset this). If you're using bash, you can run shopt -s checkwinsize
beforehand, which will tell it to re-compute those values once top exits. Otherwise, you can just backup/restore those values (or just resize the window).
You may want to try this out. This will print the only one instance of top
with fixed width and exits so you can get the output.
top -n1 -w80
You may even pipe the output to a file.
top -n1 -w80 > top_output.txt
You could design a batch screen that includes top -b -n 1 and ps, for example:
while (true)
do
clear
top -b -n 1
ps
sleep 5
done
This will handle displaying:
Trying increasing the sreen output width using below command.
export COLUMNS=197 top -u -cbn1 >top.output
Here 197 is just a varaible. Try increasing as per your requirement and detailed output you require.
htop
for a much nicer interface totop
. It will let you scroll with the arrow keys.