
Scenario and Use Case
This may be on Linux and macOS.
You are running a ps -ef or ps aux command and piping the output to grep gunicorn. You want to capture all the gunicorn process IDs and kill them.
The problem is when you run a command like this, you see the grep command too in the process list.
ps -ef | grep gunicorn
There is a way to prevent the grep command from showing up in the process list. Read on for the solution.
Solution 1: Use brackets[]
Surround the first letter of the search string with brackets [ ], like this:
ps -ef | grep '[g]unicorn'
You will not see the grep command in the process list.
Environments: Linux, macOS
Solution 2: Pipe to grep -v grep
Pipe the ps -ef | grep gunicorn command output to grep -v grep. That will prevent the grep command from showing up in the process list.
ps -ef | grep gunicorn | grep -v grep
Environments: Linux, macOS
Conclusion
Hope this blog post helped you in some way. If you would like more scenarios involving ps, grep or awk, let me know and I'll add them to this blog post. Thanks for reading.
Related Posts
If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.