Consider the following command:

watch -d "ps -ef | grep java"

It gives following output:

kshitiz  11369 11285  0 Oct13 ?        00:06:02 /usr/lib/jvm/jdk1.7.0_40/jre/bin/java -Djava.awt.headless=true -Didea.version==14.1.2 -Xmx512m -Dfile.e

The output beyond -Dfile.e is truncated or flows off screen. How can I scroll to see the output or word wrap it?

Using fold without watch: enter image description here

Using fold with watch: enter image description here


Pipe the output to fold to wrap the output at a specified width (defaultly 80):

watch -d "ps -efww | grep '[j]ava' | fold -s"
  • Use the -w flag of ps for wide output, and twice for unlimited output.
  • fold -s breaks at spaces.
  • Also notice the grep command. I changed java to [j]ava. This way the grep process will not match himself in the ps output.
  • 1
    Though fold seems to work well by itself. With watch the output is still getting cut at -Dfile.e. – Kshitiz Sharma Oct 14 '15 at 8:07

In addition:

You can also try specifying the width; this will make full use of your screen width.

In my case, the following gives a perfectly formed output. Do customize the width parameter as per you monitor/terminal size:

watch -d "ps -ef --width 1000 | grep java | grep -v grep  "

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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