Created
August 13, 2023 15:19
-
-
Save Seltyk/f8deaba6e367496f26222f784ede9c4c to your computer and use it in GitHub Desktop.
Destroy any process matching a PCRE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Nuclear option: kill any program whose process/command matches a PCRE. | |
# Options for `kill` are passed directly to it, e.g. `nuke -9 foo` runs `kill -9 pidof_foo`. | |
# Note: a more portable alternative to $@[-1] may be to `eval last=\$$#` then use `$last`. | |
# Note: making $@[1,-2] more portable might be a bit harder. I have no clue how it'd be done. | |
[[ $# -eq 0 ]] && echo "Usage: nuke [KILLOPTS] PROG" && return 1 || ps ax | grep -iP "^(?!.*grep).*$@[-1]" | awk '{print $1}' | xargs -I {} kill $@[1,-2] {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment