You can also handle ps
output a little better.
ps --width ${n:-$COLUMNS} ${opts} #set ps terminal width
ps -ww ${opts} #no word wrap
ps -o ${only_interesting_output} ${opts} #trim output
That will tell ps
to parse its output to your specifications as necessary.
Of course, if you don't word wrap, though, then you've got the problem of missing info. Do you really need all of it for all processes? Open it in a pager if so:
ps ww ${opts} | $PAGER
If not, specify what you do want to see:
ps -o args= -p $pid
Alternatively you can explicitly inform ps
of your terminal --width
:
man ps
...
w
Wide output. Use this option twice for unlimited width.
-w
Wide output. Use this option twice for unlimited width.
--width n
Set screen width.
The --width
thing works exactly to your requested specs without having to involve any additional filters or ancillary processes (which will likely only clutter your -aux
output even more). And with $COLUMNS
as shown above and as Stephane points out it will even work dynamically.
It's probably worth noting, though, that I find people often try to add these kinds of unnecessary filters so they can accomodate a |pipe
through another filter to parse output which is also pretty likely to be unnecessary. Of course, by people I mostly mean me.
The -o
utput operand I mention above allows you to filter which columns ps
displays, and when you add the =
assigment you can even name the column as you please. I leave the assignment empty and hand it a target -p
rocess $pid
so the only output from ps
at all is the $pid
command name and its args
at invocation. And -o
barely scratches the surface of how you can define what ps
will or won't display. This is the direction I would recommend you take, especially via:
man ps
...
To see every process on the system using BSD syntax:
ps ax
ps axu
To print a process tree:
ps -ejH
ps axjf
To get info about threads:
ps -eLf
ps axms
To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM
To see every process running as root (real & effective ID) in user format:
ps -U root -u root u
To see every process with a user-defined format:
ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
ps -Ao pid,tt,user,fname,tmout,f,wchan
Print only the process IDs of syslogd:
ps -C syslogd -o pid=
Print only the name of PID 42:
ps -p 42 -o comm=
tput rmam; ps aux
– Stéphane Chazelas Apr 18 '14 at 5:53zsh
,ksh93
orbash
store the terminal width in$COLUMNS
– Stéphane Chazelas Apr 18 '14 at 5:56