2012-08-08 76 views
6

是否有任何工具將文件從給定起始偏移量複製到給定(結束)偏移量。我也想確認該工具通過運行md5sum正確複製指定的字節。一些這樣的事從給定'x'(起始)偏移量複製文件到給定'y'(結束)偏移量的工具

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 

我知道的md5sum沒有-s和-e的選項,但我想給出的源文件和目標文件中的一些工具來確認。在此先感謝

回答

11

爲1),可以使用dd

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

對於2)我真的不知道這是用標準工具實現的。

[編輯]

啊哈,找到了一種方法:

對於2)

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

而對於3)

md5sum /path/to/destination/file 
+0

真棒,它完美。再次感謝:) – Viswesn 2012-08-08 15:27:41

+0

乾杯:)不客氣。 – favoretti 2012-08-08 15:28:25