我正在尝试使用以下命令从 Ubuntu 中的/proc/cpuinfo 中 grep 模型:
cat /proc/cpuinfo | grep 'model'
但我得到 2 行作为输出:
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
我只会得到这一行作为输出:
model : 60
我该怎么做?
最佳答案
要仅获取第一行,只需使用 head
:
cat /proc/cpuinfo | grep 'model' | head -1 # <--- This is what you realy asked
要仅获取最后一行,您可以使用 tail
:
cat /proc/cpuinfo | grep 'model' | tail -1
如果你想要 n'th
您可以同时使用以下行:
cat /proc/cpuinfo | grep 'model' | head -n | tail -1
关于regex - 来自/proc/cpuinfo的grep信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38585835/