PS command ouput with fixed width for each column

aixsolarisunix

I am trying to execute some PS commands on IBM AIX and Solaris. The output I get is not properly formatted, I want to see the values for each column with some fixed width.

Is there anyway I can mention width for each column that PS command shows?

Best Answer

In GNU ps, you can specify the field width to widen a field:

ps axw o user:10,pid:8,%cpu:8,cmd

In Solaris and AIX, you can specify the column header to widen columns. Here, I'm padding with hyphens, but you could use something else:

ps -ef -o user=---USER---,pid=---PID--,%cpu=--%CPU--,cmd

This also works for GNU ps.