解释此命令如何查找5个CPU最密集的进程



如果我有命令

ps | sort -k 3,3 | tail -n 5

这是如何找到5个CPU最密集的进程的?

我知道它会处理所有的过程,通过-k选项根据一列对它们进行排序,但3,3是什么意思?

您可以阅读sort(linux中的info sort(的官方手册;特别是,您对以下摘录感兴趣:

‘-k POS1[,POS2]’
‘--key=POS1[,POS2]’
Specify a sort field that consists of the part of the line between
POS1 and POS2 (or the end of the line, if POS2 is omitted),
_inclusive_.

,跳过几段,

Example: To sort on the second field, use ‘--key=2,2’ (‘-k 2,2’).
See below for more notes on keys and more examples.  See also the
‘--debug’ option to help determine the part of the line being used
in the sort.

因此,基本上,3,3强调只应考虑第三列进行排序,其他列将被忽略。

最新更新