How to wrap output of watch command

foldwatch

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

Best Answer

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.
Related Question