Skip to content

Instantly share code, notes, and snippets.

@nuryslyrt
Forked from v9n/kill_with_pid_awk_sed.sh
Created April 3, 2018 11:03
Show Gist options
  • Save nuryslyrt/c606e067938d98f6415195fd6a3e9644 to your computer and use it in GitHub Desktop.
Save nuryslyrt/c606e067938d98f6415195fd6a3e9644 to your computer and use it in GitHub Desktop.
Kill a procees with pid getting on the fly via awk
#For example, we want to kill Netbeans
ps -ef | grep beans | awk ' $6 != "ttys000" {print$2;}' | xargs kill {}
#Or get the first line only (to aovid getting grep command itself)
ps -ef | grep beans | head -n 1 | awk ' {print$2}' | xargs kill {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment