How to wrap output of watch command?

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.

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  "

Tags:

Watch

Fold