20

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.

migrated from stackoverflow.com Jan 27 '12 at 2:13

This question came from our site for professional and enthusiast programmers.

  • What command generates your output? – Tichodroma Jan 26 '12 at 13:28
  • I know this doesn't directly answer your question, but I'd look at htop for a much nicer interface to top. It will let you scroll with the arrow keys. – Daniel Arndt Jan 26 '12 at 13:29
  • Can you clarify why didn't reducing font size work? – Stephen Quan Jan 27 '12 at 13:05
  • it works but not enough for me to see the whole line.. the command line is rather long – sureshvv Jan 30 '12 at 6:11
10

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.

  • 1
    You need to check the man page on your system; these options do not exist in all versions of top. – Scott Feb 26 '18 at 23:58
19

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.

  • That just displays the full command line by default - or actually whatever can be made visible in one line. I don't see any scrolling ability. Are you saying I just have to set my window to a larger width? – sureshvv Jan 26 '12 at 14:38
  • Yes, that to begin with. What type of window are you using? is it a Putty, Dos command terminal, Gnome terminal ? any of these will allow you to scroll horizontally. – ring bearer Jan 26 '12 at 14:43
  • not seeing horizontally scrolling in PuTTY – bbodenmiller Jun 6 '18 at 5:22
8

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.

  • This does not answer the question but is a suggestion for a different program. htop is a nice program indeed but the question was about top's output. Please remain on topic. – drumfire Dec 27 '13 at 20:19
  • 2
    @drumfire offering alternatives is perfectly valid and on topic. This should be obvious by the fact that the OP accepted this answer almost three years ago. – terdon Dec 28 '13 at 1:06
3

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).

0

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:

  • PID
  • CPU
  • Untruncated command line
0

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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.