给定一个包含10个文件的.zip或.rar存档,每个文件都有不同的扩展名。
鉴于我只想要.jpg文件。
如何在其中提取* .jpg而不必提取其他9个文件?
答案 0 :(得分: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.
答案 1 :(得分:0)
tar -xf test.tar --wildcards --no-anchored '*.jpg'
答案 2 :(得分:0)
您可以使用:
while read -r f; do
tar -xf "$zipFile" "$f"
done < <(tar tf "$zipFile" | grep '\.jpg')