Force wrapping the long output lines that aren't so in terminal

Usually when the long lines are output in terminal/console/xterm, they will be wrapped automatically. However, there are cases that are not. ps is one of such cases -- it cuts the output right at the windows width.

 ps ax | grep [d]nsmasq
 4459 ?        S      0:03 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsm

For the dnsmasq, even I maximize my xterm, the output is still being cut.

I've tried,

 $ ps ax | fold | grep [d]nsmasq
 4459 ?        S      0:03 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsm

 $ ps ax | grep [d]nsmasq | fold
 4459 ?        S      0:03 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsm

 $ ps ax | grep [d]nsmasq | fold --spaces
 4459 ?        S      0:03 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsm

Such cutting make ps seems like not writing to standard output, but its responding to grep proves otherwise. But how come the fold not working then?

How to wrapping such long lines to show everything instead of cutting to the windows' width?


Solution 1:

Duh, found the answer soon after I asked it.

COLUMNS=500 ps ax | grep [d]nsmasq | fold

The same trick works for dpkg as well.

Solution 2:

Check the man page. Compare these 3 outputs:

ps ax
ps axw
ps axww