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


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?


One option, feed the output to <a href="/questions/tagged/awk" class="post-tag" title="show questions tagged 'awk'" rel="nofollow">awk</a>

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


  • SQL Service Broker: Collecting data from distributed sources.
  • MATLAB quick find of a vector in matrix
  • Java, will (low + high) >>> 1 overflow?
  • Linux over commit heuristic
  • get passwords from chrome
  • How to use animated gif in Firemonkey?
  • Android onKey w/ virtual keyboard
  • How to return DataSet (xsd) in WCF
  • Low TTL with Leveled Compaction, should I reduce gc_grace_seconds to improve read performance withou
  • close() was never explicitly called on database
  • Eliminate partial duplicate rows from result set
  • How to assign byte[] as a pointer in C#
  • Unable to get column index with table.getColumn method using custom table Model
  • How can I extract results of aggregate queries in slick?
  • GridView breaks while scrolling
  • How to change the font size of a single index for UISegmentedControl?
  • Time complexity of a program which involves multiple variables
  • Word Open XML Mail Merge
  • Replace value with Factor in r data.table
  • Atlas images wrong size on iPad iOS 9
  • Database structure design with variable amounts of fields
  • Change multiple background-images with jQuery
  • Android screen density dpi vs ppi
  • Submit form in a displaytag pagination
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Change an a tag attribute in JavaScript based on screen width
  • Delete MySQLi record without showing the id in the URL
  • Unanticipated behavior
  • Comma separated Values
  • python regex in pyparsing
  • Trying to get generic when generic is not available
  • How do I configure my settings file to work with unit tests?
  • Android Google Maps API OnLocationChanged only called once
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • Busy indicator not showing up in wpf window [duplicate]
  • Binding checkboxes to object values in AngularJs
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF
  • How can I use threading to 'tick' a timer to be accessed by other threads?