How to find all processes with a specific string in their name and kill them all (in linux command line using ps, grep and awk)

Context

You want to find all the processes of, for example, visual studio code, and kill them all for the command line in linux.

To find all the processes ids for a particular app you can use the following:

Find all the processes for a particular app

ps -d | grep app_name | awk '{print $1}'

For example to find all the processes for visual studio code (process name is code, you would type

ps -d | grep code | awk '{print $1}'

Kill all the processes for that particular app

If you want to kill all those processes, just prepend kill and use the ids as arguments

kill $(ps -d | grep code | awk '{print $1}')

References

Comments

Comments powered by Disqus