grep tips

用了linux那麼久了. 今天才知道這個功能. 真是要打屁股!!

先印出 cpuinfo 的資訊這樣看下列範例會比較清楚.
# cat /proc/cpuinfo

processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 4
model name : Intel(R) Pentium(R) 4 CPU 3.20GHz
stepping : 3
cpu MHz : 2800.000
cache size : 2048 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 3
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc up pni monitor ds_cpl est cid cx16 xtpr
bogomips : 6388.48

假設我要抓 CPU 資訊 model name. 指令為 :
# cat /proc/cpuinfo | grep model\ name

model name : Intel(R) Pentium(R) 4 CPU 3.20GHz

要抓 CPU 資訊及前一行指令為 :
# cat /proc/cpuinfo | grep model\ name -B1

model : 4
model name : Intel(R) Pentium(R) 4 CPU 3.20GHz

要抓 CPU 資訊及後一行指令為 :
# cat /proc/cpuinfo | grep model\ name -A1

model name : Intel(R) Pentium(R) 4 CPU 3.20GHz
stepping : 3

要抓 CPU 資訊及前後兩行指令為 :
# cat /proc/cpuinfo | grep model\ name -C2

cpu family : 15
model : 4
model name : Intel(R) Pentium(R) 4 CPU 3.20GHz
stepping : 3
cpu MHz : 2800.000

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.