如何计算结果

Moh*_*ani 2 command-line

如何计算结果?当您编写命令并出现一些结果时。任何方式来计算它们。例如,如果我想要具有 python word 的应用程序有多少结果。

dpkg -l | grep python
Run Code Online (Sandbox Code Playgroud)

ste*_*ver 6

在 grep 的情况下,您可以简单地使用该-c选项

dpkg -l | grep -c python
Run Code Online (Sandbox Code Playgroud)

man grep

   -c, --count
          Suppress normal output; instead print a count of matching  lines
          for  each  input  file.  With the -v, --invert-match option (see
          below), count non-matching lines.  (-c is specified by POSIX.)
Run Code Online (Sandbox Code Playgroud)

更一般地,您可以将命令输出通过管道传输到wc命令,例如

 dpkg -l | grep python | wc -l
Run Code Online (Sandbox Code Playgroud)