[ubuntu-florida] Avoid That grep Command in grep Output
j.e.aneiros
jesus.aneiros at gmail.com
Wed Sep 15 16:19:49 BST 2010
And by the way, something the author didn't tell: In Linux we can avoid the
whole grep filtering with a simple ps -C <command_name>
janeiros at harlie:~$ ps -C bash
PID TTY TIME CMD
13235 tty1 00:00:00 bash
17798 pts/0 00:00:00 bash
Of course, the output is a little bit different than the one from ps ax.
On Wed, Sep 15, 2010 at 10:48 AM, Matt Miller <matt.s.miller at gmail.com>wrote:
> This is how I would go about it:
>
> $ pgrep bash | xargs ps -fp
> UID PID PPID C STIME TTY STAT TIME CMD
> millermx 3104 3099 0 08:48 pts/0 Ss+ 0:00 /bin/bash
> millermx 13662 13659 0 09:58 pts/1 Ss 0:00 /bin/bash
> millermx 16247 13659 0 10:36 pts/2 Ss 0:00 /bin/bash
> millermx 16405 13659 1 10:46 pts/3 Ss 0:00 /bin/bash
>
>
> On Wed, Sep 15, 2010 at 10:37 AM, Miano, Steven M.
> <Steven.Miano at mybrighthouse.com> wrote:
> >
> > I've always just done:
> >
> > $ps aux | grep bash | grep -v grep
> >
> > Is there something wrong with that?
> >
> > On the error in the book that's interesting, I wasn't able to reproduce
> the same error using the same command successively....8.04/LTS/i386
> >
> > ~Steven
> >
> > ________________________________________
> > From: ubuntu-us-fl-bounces at lists.ubuntu.com [
> ubuntu-us-fl-bounces at lists.ubuntu.com] On Behalf Of j.e.aneiros [
> jesus.aneiros at gmail.com]
> > Sent: Wednesday, September 15, 2010 9:39 AM
> > To: Mailing list for Ubuntu Florida LoCo Team
> > Subject: [ubuntu-florida] Avoid That grep Command in grep Output
> >
> > Hello everyone,
> >
> > I'm planning to send everyday at least a message to the list with
> something interesting about Linux. This is the first one.
> >
> > One week ago I bought the book "Official Ubuntu Server Book, The (2nd
> Edition)". Being a command line fan I went directly to the section "Cool
> tips and tricks". I started reading and I found out that the explanation of
> the first trick is in a certain way wrong.
> >
> > The idea behind the trick is to avoid the appearance of grep in resulting
> list for a command like:
> >
> > janeiros at harlie:~$ ps ax | grep bash
> > 13235 tty1 S 0:00 -bash
> > 13256 tty1 S+ 0:00 /bin/bash /usr/bin/startx
> > 16911 pts/0 Ss+ 0:00 -bash
> > 17005 pts/1 Ss 0:00 -bash
> > 17152 pts/1 S+ 0:00 grep --color=auto bash
> >
> > The authors suggest a "trick" running the command in this form:
> >
> > janeiros at harlie:~$ ps ax | grep [b]ash
> >
> > How come when I try the trick is OK the first time and wrong at the
> second one?
> >
> > janeiros at harlie:~$ ps ax | grep [b]ash
> > 13235 tty1 S 0:00 -bash
> > 13256 tty1 S+ 0:00 /bin/bash /usr/bin/startx
> > 16911 pts/0 Ss+ 0:00 -bash
> > 17005 pts/1 Ss 0:00 -bash
> >
> > You can see grep is gone.
> >
> > And now is back:
> >
> > janeiros at harlie:~$ ps ax | grep [b]ash
> > 13235 tty1 S 0:00 -bash
> > 13256 tty1 S+ 0:00 /bin/bash /usr/bin/startx
> > 16911 pts/0 Ss+ 0:00 -bash
> > 17005 pts/1 Ss 0:00 -bash
> > 17185 pts/1 S+ 0:00 grep --color=auto bash
> >
> > Of course, I did something in between that provoked the change! What was
> it? Let see if somebody find out what was. The authors' explanation for the
> trick is not exact!
> >
> > The explanation is right there at the command line!
> >
> > If nobody finds out I'll tell you later today.
> >
> > By the way there is an alternative to the trick but it's longer.
> >
> > Have a good day!
> >
> > PS. The outputs of the commands weren't edited at all.
> >
> > --
> > J. E. Aneiros
> > GNU/Linux User #190716 en http://counter.li.org
> > perl -e '$_=pack(c5,0105,0107,0123,0132,(1<<3)+2);y[A-Z][N-ZA-M];print;'
> > PK fingerprint: 5179 917E 5B34 F073 E11A AFB3 4CB3 5301 4A80 F674
> >
> >
> > CONFIDENTIALITY NOTICE: This e-mail may contain information that is
> privileged, confidential or otherwise protected from disclosure. If you are
> not the intended recipient of this e-mail, please notify the sender
> immediately by return e-mail, purge it and do not disseminate or copy it.
> >
> > --
> > Ubuntu-us-fl mailing list
> > Ubuntu-us-fl at lists.ubuntu.com
> > Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-us-fl
>
> --
> Ubuntu-us-fl mailing list
> Ubuntu-us-fl at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-us-fl
>
--
J. E. Aneiros
GNU/Linux User #190716 en http://counter.li.org
perl -e '$_=pack(c5,0105,0107,0123,0132,(1<<3)+2);y[A-Z][N-ZA-M];print;'
PK fingerprint: 5179 917E 5B34 F073 E11A AFB3 4CB3 5301 4A80 F674
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/ubuntu-us-fl/attachments/20100915/b5bf69af/attachment.htm
More information about the Ubuntu-us-fl
mailing list