kill-byname.sh
来自「一本完整的描述Unix Shell 编程的工具书的所有范例」· Shell 代码 · 共 36 行
SH
36 行
#!/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.# -----------------------------------------------------------exit $?
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?