kill-byname.sh

来自「Shall高级编程」· Shell 代码 · 共 41 行

SH
41
字号
#!/bin/bash# kill-byname.sh: Killing processes by name.# Compare this script with kill-process.sh.#  For instance,#+ try "./kill-byname.sh xterm" --#+ and watch all the xterms on your desktop disappear.#  Warning:#  -------#  This is a fairly dangerous script.#  Running it carelessly (especially as root)#+ can cause data loss and other undesirable effects.E_BADARGS=66if test -z "$1"  # No command line arg supplied?then  echo "Usage: `basename $0` Process(es)_to_kill"  exit $E_BADARGSfiPROCESS_NAME="$1"ps ax | grep "$PROCESS_NAME" | awk '{print $1}' | xargs -i kill {} 2&>/dev/null#                                                       ^^      ^^# ---------------------------------------------------------------# Notes:# -i is the "replace strings" option to xargs.# The curly brackets are the placeholder for the replacement.# 2&>/dev/null suppresses unwanted error messages.## Can  grep "$PROCESS_NAME" be replaced by pidof "$PROCESS_NAME"?# ---------------------------------------------------------------exit $?#  The "killall" command has the same effect as this script,#+ but using it is not quite as educational.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?