Is it possible to extract a few number of bytes out of a file using dd ? The file is located on a secondary drive.

I apologize if this is a simple question however I'm no pro at command line.


If this is file:

hello world how are you today

Then this would extract world from file:

 dd bs=1 skip=6 count=5 if=file

It skips 6 bytes (hello_), reads 5 bytes (world), and ignores the rest.

So with skip, count, and bs=1 (or alternatively, when using GNU dd, using the count_bytes/skip_bytes flag), you can extract specific byte ranges at byte resolution.

| improve this answer | |
  • Thanks for the prompt reply. What about the 'if' and 'of' ? That is mainly my problem. I've tried dd if=/dev/sdb2/..../'directoryname' of=/dev/sdb2/..../'directoryname 2' bs=13172736b The below should extract a number of bytes out of a Virtual Machine's virtual hdd (.vmdk file), which resides in a folder called 'Windows 7 vmware' Actual text is dd if=/dev/sdb2/media/Used\ for\ VMs/ of=/media/Used\ for\ VMs/Windows\ 7\ vmware bs=13172736b – joebegborg07 Mar 7 '15 at 12:32
  • 5
    There is no /dev/sdb2/pathname... you can either write raw data to the device, or you have to use mount so it's /mnt/sdb2/pathname. This sounds like an X Y problem so maybe you should have asked your real question... – frostschutz Mar 7 '15 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.