1

I would like to know why ps aux | grep includes the grep command in the output but ps aux | grep "confi[g]" does not.

$ ps aux | grep config
root               50   0.0  0.0  2548368   5760   ??  Ss   14Sep16   0:29.27 /usr/libexec/configd
emesa           20534   0.0  0.0  2434840    796 s002  S+    4:41PM   0:00.00 grep config

vs.

$ ps aux | grep "confi[g]"
root            15776   0.0  0.0  2519824    940   ??  Ss   Tue11AM   0:00.08 /System/Library/PrivateFrameworks/SystemAdministration.framework/XPCServices/writeconfig.xpc/Contents/MacOS/writeconfig
root               50   0.0  0.0  2547320   5740   ??  Ss   14Sep16   0:29.27 /usr/libexec/configd
ilkkachu
  • 133,243
  • 15
  • 236
  • 397
c4f4t0r
  • 649
  • 5
  • 11
  • Because `grep config` matches the line `emesa ... grep config` in `ps aux` output, but `grep confi[g]` doesn't match the corresponding line `emesa ... grep confi[g]` in `ps aux` output. – Satō Katsura Sep 29 '16 at 14:56
  • 4
    See [How can I prevent 'grep' from showing up in ps results?](http://unix.stackexchange.com/questions/74185/how-can-i-prevent-grep-from-showing-up-in-ps-results) – steeldriver Sep 29 '16 at 15:09

1 Answers1

2

Because grep "confi[g]" command searches for the "config" string and in your second case the grep "confi[g]" command does not contain the "config" string. It contains the "confi[g]" string.

It's a commonly used grep trick to avoid printing the grep command process when searching in ps output.

zuazo
  • 3,002
  • 18
  • 24