如何让一个bash脚本一个分区的偏移? [英] How to get the offset of a partition with a bash script?

查看:146
本文介绍了如何让一个bash脚本一个分区的偏移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用分手来找出我的形象的偏移量。

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

例如,分区将从 2097152

我怎样才能获得 2097152 用bash脚本?

How can I get the 2097152 with a bash script?

我大概可以解析输出,但也许还有一个更合适的方法?

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

推荐答案

一个选项,喂输出的 AWK

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

这篇关于如何让一个bash脚本一个分区的偏移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆