How to make the output of ps(1) aware of tty / pipe?

Matthew Seaman m.seaman at infracaninophile.co.uk
Fri Oct 29 07:24:04 PDT 2004


On Fri, Oct 29, 2004 at 03:37:59PM +0200, Leroy van Logchem wrote:

> How to make the output of 'ps aux' for example aware of the output being 
> piped trough grep?
> Now it breaks the lines while I would expect it to be just long lines.
> (I don't want to loose the linebreaking feature by using a -ww alias or 
> something)

Errr... that's what the -w flag to ps(1) is for.  Without the -w flag,
ps assumes it is printing to an 80 column terminal, and truncates the
lines appropriately.  With one -w flag, it assumes a 132 column
terminal, and with more than one -w flag, ps assumes an unlimited
number of columns are available.  It does that whether or not the
output is being displayed on the tty, written to a file or fed into a
pipe.  (Unlike, say, less(1), top(1) or ls(1) which can change their
behaviour according to circumstances).

Don't be confused by the line wrapping feature of the terminal: the
output might look like it's split over several lines, but really it
isn't.  Compare and contrast the effects of:

    % ps -auxww | less
    % ps -auxww | less -S

(Try hitting the left and right arrow keys while paging through the
second set of output...)

Generally, if you're grepping through the output of ps(1), you want
all of the ps output to be there.  The usual idiom is:

    % ps -auxww | grep foo

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20041029/6042fd23/attachment.bin


More information about the freebsd-questions mailing list