1

给定一个包含 10 个文件的 .zip 或 .rar 存档,每个文件都有不同的扩展名。

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

如何提取其中的 *.jpg 而无需提取其他 9 个文件?

4

3 回答 3

1

试试这个 :

unzip test.zip '*.jpg'

文件名后面的参数是要提取的文件。请参阅man unzip参数部分

   [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.
于 2014-03-28T20:08:35.743 回答
0
tar -xf test.tar --wildcards --no-anchored '*.jpg'
于 2014-03-28T20:10:01.617 回答
0

您可以使用:

while read -r f; do
    tar -xf "$zipFile" "$f"
done < <(tar tf "$zipFile" | grep '\.jpg')
于 2014-03-28T20:16:47.197 回答