Just thought would share it here. I just wanted to list of processes in unix in a single go. After trying some of the syntax I got it right. Here it is…
ps -aux | grep -i "test" | awk '{print $2}' | xargs kill -9
Bit of explanation below :
ps -aux –> Lists all the processes running in the machine in the below order.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
grep -i “test” –> filters all the row containing word ‘test’ in this case. Here you can change anything you want to filter or kill..!
awk ‘{print $2}’ –> Prints the second column i.e the PID (process ID)
xargs kill -9 –> Passes them as arguments to the kill command. -9 is the ‘force kill’ signal.
Hope it helps someone looking for this. Do share if any better way of doing this.