pgrep 搜索多个单词

Nik*_* VJ 5 linux pgrep

我用来pgrep查找正在运行的进程有一些单词

> pgrep -f "otp"
2345
2343
Run Code Online (Sandbox Code Playgroud)

识别了多个进程。命令行中还有另一个单词可以帮助我将确切的过程归零。所以,我想搜索两个术语,并且两个术语都应该在那里。不幸的是,我只看到 OR 组合的示例和帮助,如下所示:

> pgrep -f "otp|place1"
2345
2343
3632
Run Code Online (Sandbox Code Playgroud)

这是行不通的,因为它是一个 OR 条件。我的搜索模式中需要一个 AND 条件。

pgrep 参考: https: //linux.die.net/man/1/pgrep

模式:指定用于匹配进程名称或命令行的扩展正则表达式。

如何使用 pgrep 搜索 AND 组合而不是 OR 的两个单词?

Nik*_* VJ 3

找到了一种方法,条件是它们应该按顺序:将单词分开.*

> pgrep -f "otp.*place1"
2345
Run Code Online (Sandbox Code Playgroud)