pgrep使用正则表达式作为模式样式.我想念grep的-i选项,告诉pgrep,我正在搜索不区分大小写.
另一种选择是
ps ax | grep -i PATTERN
Run Code Online (Sandbox Code Playgroud)
但是我必须使用PID发送KILL信号.使用pgrep和pkill组合,我可以使用相同的模式来杀死应用程序.
如何在bash上动态使用正则表达式的REG_ICASE?
kill `ps ax | grep -i PATTERN | awk '{ print $1 }'`
Run Code Online (Sandbox Code Playgroud)
将使用神奇的`杀死所有进程匹配不区分大小写的进程
[仅限 BSD]
[ FreeBSD pgrep 手册页]
来自pgrep 的手册页:man pgrep在选项下i
-i Ignore case distinctions in both the process table and the
supplied pattern.
Run Code Online (Sandbox Code Playgroud)
因此,我们可以使用如下选项i:
pgrep -fi 'PATTERN'
Run Code Online (Sandbox Code Playgroud)
IE:
pgrep -f 'chrome'
echo $?
1
Run Code Online (Sandbox Code Playgroud)
但包括-fi选项有效:
pgrep -fi 'ChRoMe'
Run Code Online (Sandbox Code Playgroud)
输出:
> 872
910
41391
60087
60090
60092
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2833 次 |
| 最近记录: |