当前位置: 技术问答>linux和unix
bash script /proc/partitions取字串問題
来源: 互联网 发布时间:2016-11-06
本文导语: cat /proc/partitions major minor #blocks name 3 0 160086528 hda 3 1 10482381 hda1 3 2 10482412 hda2 3 3 10482412 hda3 3 4 128632455 hda4 3 64 312571224 hdb ...
cat /proc/partitions
major minor #blocks name
3 0 160086528 hda
3 1 10482381 hda1
3 2 10482412 hda2
3 3 10482412 hda3
3 4 128632455 hda4
3 64 312571224 hdb
3 65 312568641 hdb1
如果要取出hda2的blocks ,10482412 該怎樣下指令呢
cat /proc/partitions|grep hda2|???
major minor #blocks name
3 0 160086528 hda
3 1 10482381 hda1
3 2 10482412 hda2
3 3 10482412 hda3
3 4 128632455 hda4
3 64 312571224 hdb
3 65 312568641 hdb1
如果要取出hda2的blocks ,10482412 該怎樣下指令呢
cat /proc/partitions|grep hda2|???
|
awk '/hda2/ {print $3}' /proc/partitions
|
cat /proc/partitions|grep hda2| tr -s " " | cut -d" " -f4
|
awk 'if($NR=3) {print $4 }' /proc/partitions