Why does enclosing a single char in brackets in a regex exclude the grep itself when grepping ps?

前端 未结 2 1156
梦谈多话
梦谈多话 2021-01-19 19:17

If I perform the following grep on my Linux box:

$ ps -ef | grep bash
root      2286     1  0 Jun06 ?        00:03:15 /bin/bash /etc/init.d/zxy100wd
wmiller          


        
2条回答
  •  轮回少年
    2021-01-19 19:47

    Fedorqui nails it with the explanation of the character class trick. I just wanted to point out the other method I used quite often albeit a bit longer than what you already know was to use -v option of grep command.

    ps -ef | grep bash | grep -v grep
    

提交回复
热议问题