在里面提取两个档案来提取cpio.gz

时间:2017-04-26 11:14:12

标签: linux unix gz cpio

我已经使用命令创建了cpio.gz: cat a.cpio.gz b.cpio.gz > c.cpio.gz

现在我要将此c.cpio.gz文件解压缩到b.cpio.gz和a.cpio.gz.我怎么能做到这一点?

1 个答案:

答案 0 :(得分:0)

好的,我有2个.gz个文件,a.txt.gzb.txt.gz。然后:

$ cat a.txt.gz b.txt.gz > c.txt.gz
$ hexdump -C c.txt.gz
00000000  1f 8b 08 08 f7 a3 00 59  00 03 61 2e 74 78 74 00  |.......Y..a.txt.|
00000010  4b 2c 4e e1 4a 24 80 01  a9 66 ae 58 24 00 00 00  |K,N.J$...f.X$...|
00000020  1f 8b 08 08 01 a4 00 59  00 03 62 2e 74 78 74 00  |.......Y..b.txt.|
00000030  2b 2c 4f e5 2a 24 0a 73  a5 72 01 00 70 24 d5 0a  |+,O.*$.s.r..p$..|
00000040  2d 00 00 00                                       |-...|

从0x00和0x20开始查看那些1f 8b 08,它们是.gz个文件(based on the article I referred to in the OP's comments)的BOF标记。现在有些awk:

$ awk '
BEGIN { RS="\x1f\x8b\x08"; ORS="" }  # set the marker to RS
NR==2 { print RS $0 > "a2.txt.gz" }  # output the marker and what's after first marker
NR==3 { print RS $0 > "b2.txt.gz" }  # output the marker and what's after the second
' c.txt.gz

生成2个文件,根据我的diff,它们与原始文件相同。

相关问题