38

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.

4
  • What command generates your output?
    – Tichodroma
    Jan 26, 2012 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, 2012 at 13:29
  • Can you clarify why didn't reducing font size work? Jan 27, 2012 at 13:05
  • it works but not enough for me to see the whole line.. the command line is rather long
    – sureshvv
    Jan 30, 2012 at 6:11

7 Answers 7

31

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.

6
  • 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, 2012 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. Jan 26, 2012 at 14:43
  • not seeing horizontally scrolling in PuTTY Jun 6, 2018 at 5:22
  • This does not show thread names with -H unfortunately. Sep 14, 2022 at 17:01
  • You can also press c while top is running. Jan 28, 2023 at 19:21
25

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.

6
  • 3
    You need to check the man page on your system; these options do not exist in all versions of top. Feb 26, 2018 at 23:58
  • 2
    in my ubuntu 18.04 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.
    – gilad905
    Dec 18, 2019 at 12:58
  • I wasn't aware of -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.
    – bartgol
    Aug 26, 2022 at 22:29
  • Thanks, the -w 512 argument really did the trick Jun 3, 2023 at 9:54
  • What is the rationale behind "maximum width is 512 characters"? What if 512 is not sufficient?
    – pmor
    Feb 1 at 11:04
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.

2
  • 1
    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, 2013 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, 2013 at 1:06
4

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

3

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
1

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

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .