TIL: grep bracket [t]rick

May 27, 2026

When you use grep to search for a running process, you often see the grep command itself in the results:

$ ps aux | grep 'python'
user  1234  python myapp.py
user  5678  grep python      # <-- unwanted!

To avoid it you wrap the first letter in brackets:

$ ps aux | grep '[p]ython'
user  1234  python myapp.py  # only the real match!

This works because [p]ython matches python but it doesn't match the string [p]ython. So grep filters itself out automatically.