Question

Given a .zip or .rar archive containing 10 files, each with different extensions.

Given I only want the .jpg file in it.

How to extract the *.jpg in it without having to extract the 9 other files ?

Was it helpful?

Solution

Try this :

unzip test.zip '*.jpg'

The argument after the filename is the file to be extracted. See 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.

OTHER TIPS

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

You can use:

while read -r f; do
    tar -xf "$zipFile" "$f"
done < <(tar tf "$zipFile" | grep '\.jpg')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top