6

如果我在文件系统上有一个文件,我可以用 dd 做这样的事情:

dd  if=/my/filewithaheader.bin bs=32k skip=1 | gunzip | tar tvf

但是,如果我尝试这样的事情:

./commandthatputsstuffonstdout |  dd  bs=32k skip=1 | gunzip | tar tvf

我得到错误: dd: 'standard input': cannot skip to specified offset

我该如何解决这个问题,可以用 dd 完成,还是有另一个我可以使用的 unix 命令

4

3 回答 3

5

你可以使用tail. 说:

./commandthatputsstuffonstdout | tail -c +1025 ...

跳过1024命令产生的输出的第一个字节。

来自man tail

   -c, --bytes=K
          output the last K bytes; alternatively,  use  -c  +K  to  output
          bytes starting with the Kth of each file
于 2013-11-23T10:22:48.690 回答
3

我也遇到了这个问题,使用fullblockiflag 可以防止短读和随后的中止。

例子:

gzip -d < ./disk_image.dd.gz | \
    dd bs=4M skip=32768 iflag=fullblock,skip_bytes of=./partial_image.dd
于 2017-12-13T13:44:45.217 回答
0

答案有点晚,但这个 dd 示例对我有用。

创建示例源文件:

$ dd if=/tmp/somefile of=/tmp/test skip=50 bs=100 count=1

跳过 50 个字节并将其后的 10 个字节复制到 test_skip 文件:

$ dd if=/tmp/test of=/tmp/test_skip skip=50 bs=1 count=10
10+0 records in
10+0 records out
10 bytes (10 B) copied, 8.2091e-05 s, 122 kB/s

或来自标准输入的数据:

cat /tmp/test| dd of=/tmp/stdin bs=1 skip=50 count=1

验证输出:

$ hexdump /tmp/test
0000000 ebf3 e8fd df1b 0aa1 faa3 1fba 1817 1267
0000010 1402 f539 fb69 f263 f319 084b 0b26 1150
0000020 182a f98d 030c e0b0 e47c f13d ef3b 1146
0000030 0b7e 0f72 0e58 f2bd f403 ee95 e529 0567
0000040 f88e 1994 0e83 12e5 11e7 fd4b 032f f4f0
0000050 fc9d 010a 0ab6 06b6 1224 f5cb 01e4 e67a
0000060 ebe0 f1a0                              
0000064

$ hexdump /tmp/test_skip
0000000 0f72 0e58 f2bd f403 ee95

源文件偏移量 50 为字节:0x0f

于 2016-03-31T07:33:08.053 回答