2014-03-28 41 views
1

给定一个包含10个文件的.zip或.rar文件,每个文件具有不同的扩展名。如何从档案中只提取一种文件?

鉴于我只想在其中的.jpg文件。

如何提取* .jpg而不必提取其他9个文件?

+0

似乎答案是就在附近。 – Hugolpz

+0

实际上部分做到了:http://stackoverflow.com/questions/9356849/ – Hugolpz

回答

1

试试这个:

unzip test.zip '*.jpg' 

在文件名后的参数是要提取的文件。见man unzip Arguments section

[file(s)] 
      An optional list of archive members to be processed, separated 
      by spaces. (VMS versions compiled with VMSCLI defined must 
      delimit files with commas instead. See -v in OPTIONS below.) 
      Regular expressions (wildcards) may be used to match multiple 
      members; see above. Again, **be sure to quote expressions that 
      would otherwise be expanded** or modified by the operating system. 
+0

这不会在当前shell中扩展'* .jpg'吗? – anubhava

+0

@anubhava确实需要报价,请参阅编辑 –

+0

@EdouardLopez:谢谢! – Hugolpz

0
tar -xf test.tar --wildcards --no-anchored '*.jpg' 
0

您可以使用:

while read -r f; do 
    tar -xf "$zipFile" "$f" 
done < <(tar tf "$zipFile" | grep '\.jpg')