使用linux命令提取总高清内存和高清内存使用情况

时间:2022-08-06 16:58:59

I'm looking forward to extract disk memory usage from top command using grep command an save it into a variable available for the bash interpreter.

我期待使用grep命令从top命令中提取磁盘内存使用量,并将其保存到可用于bash解释器的变量中。

2 个解决方案

#1


... and I assume you failed to grep those part from top's output without understanding why...

......而且我认为你没有理解为什么......从顶部的输出中没有看到那些部分......

This happens to many users, the reason is that the top command has a somewhat unexpected output strategy. It does make sense, once you dig into it, but as said, unexpected:

这种情况发生在很多用户身上,原因是top命令有一些意想不到的输出策略。一旦你深入研究它,它确实有意义,但正如所说,出乎意料:

By default, top does not write it's output to stdout which is the precondition so that you can grep through it's output. However if you take a look into it's man page (man top), then you will spot the -b flag you can use to invoke it such that it does write it's output to stdout. This enables you to process the output as you are used to under unixoid environments, for example by "grepping" parts of the output for further usage.

默认情况下,top不会将其输出写入stdout,这是前提条件,因此您可以通过它的输出进行grep。但是,如果您查看它的手册页(man top),那么您将发现可用于调用它的-b标志,以便将其输出写入stdout。这使您可以像在unixoid环境下一样处理输出,例如通过“grepping”部分输出以供进一步使用。

Together with the -n flag which allows you to limit the commands output to a single iteration (again: see the man page) you can construct a simple extraction command:

与-n标志一起允许您将命令输出限制为单个迭代(再次:请参见手册页),您可以构造一个简单的提取命令:

top -b -n 1|grep "KiB"

I think from here on you will find the way by yourself :-) Have fun!

我想从这里你会发现自己的方式:-)玩得开心!

#2


top provides no information about your hard disk usage. Take a look at df.

top不提供有关硬盘使用情况的信息。看看df。

#1


... and I assume you failed to grep those part from top's output without understanding why...

......而且我认为你没有理解为什么......从顶部的输出中没有看到那些部分......

This happens to many users, the reason is that the top command has a somewhat unexpected output strategy. It does make sense, once you dig into it, but as said, unexpected:

这种情况发生在很多用户身上,原因是top命令有一些意想不到的输出策略。一旦你深入研究它,它确实有意义,但正如所说,出乎意料:

By default, top does not write it's output to stdout which is the precondition so that you can grep through it's output. However if you take a look into it's man page (man top), then you will spot the -b flag you can use to invoke it such that it does write it's output to stdout. This enables you to process the output as you are used to under unixoid environments, for example by "grepping" parts of the output for further usage.

默认情况下,top不会将其输出写入stdout,这是前提条件,因此您可以通过它的输出进行grep。但是,如果您查看它的手册页(man top),那么您将发现可用于调用它的-b标志,以便将其输出写入stdout。这使您可以像在unixoid环境下一样处理输出,例如通过“grepping”部分输出以供进一步使用。

Together with the -n flag which allows you to limit the commands output to a single iteration (again: see the man page) you can construct a simple extraction command:

与-n标志一起允许您将命令输出限制为单个迭代(再次:请参见手册页),您可以构造一个简单的提取命令:

top -b -n 1|grep "KiB"

I think from here on you will find the way by yourself :-) Have fun!

我想从这里你会发现自己的方式:-)玩得开心!

#2


top provides no information about your hard disk usage. Take a look at df.

top不提供有关硬盘使用情况的信息。看看df。