pgrep 仅当前用户

Noi*_*art 6 ps

我想知道有什么理由pgrep让它只对当前用户起作用。-u让我提供姓名,我不知道当前用户的姓名,我只知道我只需要当前用户。

谢谢

Wil*_*ard 7

您可以使用 UID名称,如您所见man pgrep

   -u euid,...
          Only match processes whose effective user ID is listed.  Either the
          numerical or symbolical value may be used.

   -U uid,...
          Only match processes whose real user ID is listed.  Either the 
          numerical or symbolical value may be used.
Run Code Online (Sandbox Code Playgroud)

如果您也不知道,只需使用命令替换:

pgrep -u "$(whoami)"
Run Code Online (Sandbox Code Playgroud)