How to get the offset of a partition with a bash script?

别等时光非礼了梦想. 提交于 2020-01-04 14:25:51

问题


I can use parted to find out the offset of my image.

sudo parted -s image.img unit B print
Model:  (file)
Disk /home/user/image.img: 107374182400B
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start     End            Size           Type     File system  Flags
 1      2097152B  107374182399B  107372085248B  primary  ext4

For example, partition starts at 2097152.

How can I get the 2097152 with a bash script?

I could probably parse the output, but perhaps there is a more suited method?


回答1:


One option, feed the output to awk

sudo parted -s image.img unit B print | 
awk '/^Number/{p=1;next}; p{gsub(/[^[:digit:]]/, "", $2); print $2}' 


来源:https://stackoverflow.com/questions/20181695/how-to-get-the-offset-of-a-partition-with-a-bash-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!