Search code examples
shellterminalunzipunrar

How to extract only one kind of file from the archive?


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 ?


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.