Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to copy file from given 'x' (starting) offset to given 'y' (ending) offset

Tags:

linux

unix

Is there any tool to copy a file from the given starting offset to the given (end) offset. I also want to confirm that the tool has copies specified bytes rightly by running md5sum. Some thing like this

   1) Copy source file starting from 100 byte till 250th byte
        $cp /path/to/source/file /path/to/dest/file -s 100 -e 250

   2) Create md5sum of the source file starting from 100byte till 250th byte
        $md5sum /path/of/src/file -s 100 -e 250
         xxxxxx-xxxxx-xxxxx-xxxx-xx

   3) Confirm that destination file created from step 1 is right by comparing the md5sum generated from step 2.
        $md5sum /path/of/dest/file
         xxxxxx-xxxxx-xxxxx-xxxx-xx

I know md5sum doesn't have the option of -s and -e but I would like to confirm by some tool given the source file and the destination file. Thanks in advance

like image 213
Viswesn Avatar asked Aug 08 '12 15:08

Viswesn


1 Answers

For 1) you can use dd:

# dd if=/path/to/source/file of=/path/to/destination/file bs=1 skip=100 count=250

For 2) I'm not really sure if that's achievable with standard tools.

[edit]

Aha, found a way:

For 2)

# dd if=/path/to/source/file bs=1 skip=100 count=250 | md5sum

And for 3)

md5sum /path/to/destination/file
like image 99
favoretti Avatar answered Nov 20 '22 12:11

favoretti