0

can I extract files from a specific folder inside a zip archive to a current folder?

I tried to use

unzip archive.zip folder/* 

But I got folder "folder" in my current directory. How can I extract files in "folder" to current directory?

1

You can do it by

unzip archive.zip folder/*; mv folder/* .;rm -r folder

I don't think there is an option in unzip to do it directly.

To make it shorter

f=folder; unzip archive.zip $f; mv $f .;rm -r $f

Or as a script

#!/bin/sh
unzip $1 $2
mv $2 .
rm -r $2

Run as script.sh archive.zip folder.

1

According to the answers here you can do it with single quotes ' around the folder you want to extract. Use -j for junk paths which means the archive's directory structure is not recreated. Use -d to specify what folder you want it extracted to. Below is shown extracting a folder with 1992 in the folder name from an archive that has multiple folders contained with in by running this line:

unzip -j archive.zip 'folder/to/extract/*' -d 'where/to/extract/to/'

Example:

terrance@terrance-ubuntu:/media/500GB$ unzip -l Holiday\ Lemmings\ Pack
Archive:  Holiday Lemmings Pack.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2004-10-07 23:39   Holiday Lemmings 1993/
     3597  1993-11-11 11:11   Holiday Lemmings 1993/ADLIB.DAT
      252  1993-11-11 11:11   Holiday Lemmings 1993/GREET.DAT
     1056  1993-11-11 11:11   Holiday Lemmings 1993/GROUND1O.DAT
     1056  1993-11-11 11:11   Holiday Lemmings 1993/GROUND2O.DAT
    16157  1993-11-11 11:11   Holiday Lemmings 1993/INSTALL.EXE
     3143  1993-11-11 11:11   Holiday Lemmings 1993/LEVEL000.DAT
     2868  1993-11-11 11:11   Holiday Lemmings 1993/LEVEL001.DAT
     3033  1993-11-11 11:11   Holiday Lemmings 1993/LEVEL002.DAT
     5654  1993-11-11 11:11   Holiday Lemmings 1993/LEVEL003.DAT
    59775  1993-11-11 11:11   Holiday Lemmings 1993/MAIN.DAT
     3560  1993-11-11 11:11   Holiday Lemmings 1993/TANDYSND.DAT
    25902  1993-11-11 11:11   Holiday Lemmings 1993/VGAGR1.DAT
    33123  1993-11-11 11:11   Holiday Lemmings 1993/VGAGR2.DAT
    31520  1993-11-11 11:11   Holiday Lemmings 1993/VGALEMMI.EXE
        0  2004-10-07 23:39   Holiday Lemmings 1994/
     6894  1995-07-04 14:20   Holiday Lemmings 1994/ADLIB.DAT
      438  1995-07-04 14:20   Holiday Lemmings 1994/GREET.DAT
     1056  1995-07-04 14:20   Holiday Lemmings 1994/GROUND1O.DAT
     1056  1995-07-04 14:20   Holiday Lemmings 1994/GROUND2O.DAT
       38  1995-07-04 14:20   Holiday Lemmings 1994/LEMMINGS.BAT
     2432  1995-07-04 14:20   Holiday Lemmings 1994/LEVEL000.DAT
     2633  1995-07-04 14:20   Holiday Lemmings 1994/LEVEL001.DAT
     3433  1995-07-04 14:20   Holiday Lemmings 1994/LEVEL002.DAT
     3401  1995-07-04 14:20   Holiday Lemmings 1994/LEVEL003.DAT
     3143  1995-07-04 14:20   Holiday Lemmings 1994/LEVEL004.DAT
     2868  1995-07-04 14:20   Holiday Lemmings 1994/LEVEL005.DAT
     3033  1995-07-04 14:20   Holiday Lemmings 1994/LEVEL006.DAT
     5654  1995-07-04 14:20   Holiday Lemmings 1994/LEVEL007.DAT
    58577  1995-07-04 14:20   Holiday Lemmings 1994/MAIN.DAT
     5470  1995-07-04 14:20   Holiday Lemmings 1994/TANDYSND.DAT
    25902  1995-07-04 14:20   Holiday Lemmings 1994/VGAGR1.DAT
    33123  1995-07-04 14:20   Holiday Lemmings 1994/VGAGR2.DAT
    31610  1995-07-04 14:20   Holiday Lemmings 1994/VGALEMMI.EXE
        0  2004-10-07 23:39   X-Mas Lemmings 1991/
     3597  1991-12-03 14:19   X-Mas Lemmings 1991/ADLIB.DAT
     8164  1991-12-07 14:47   X-Mas Lemmings 1991/CLOSING.EXE
     1056  1991-11-11 16:13   X-Mas Lemmings 1991/GROUND0O.DAT
     1056  1991-12-03 10:08   X-Mas Lemmings 1991/GROUND2O.DAT
    11057  1991-12-03 14:51   X-Mas Lemmings 1991/INSTALL.EXE
      756  1991-11-14 09:26   X-Mas Lemmings 1991/LEMMINGS.BAT
     2552  1991-12-03 17:40   X-Mas Lemmings 1991/LEVEL000.DAT
    59992  1991-12-03 15:24   X-Mas Lemmings 1991/MAIN.DAT
     8602  1991-12-07 14:45   X-Mas Lemmings 1991/OPENING.EXE
     3560  1991-12-03 14:25   X-Mas Lemmings 1991/TANDYSND.DAT
    28701  1991-12-03 17:44   X-Mas Lemmings 1991/TGAL.EXE
       74  1991-12-05 18:16   X-Mas Lemmings 1991/TGALEMMI.BAT
    15981  1991-12-03 10:26   X-Mas Lemmings 1991/TGAMAIN.DAT
    17957  1991-11-29 11:43   X-Mas Lemmings 1991/VGAGR0.DAT
    33123  1991-11-29 11:44   X-Mas Lemmings 1991/VGAGR2.DAT
    30469  1991-12-03 17:44   X-Mas Lemmings 1991/VGAL.EXE
       74  1991-12-05 18:16   X-Mas Lemmings 1991/VGALEMMI.BAT
        0  2004-10-07 23:39   X-Mas Lemmings 1992/
     3597  1991-12-03 14:19   X-Mas Lemmings 1992/ADLIB.DAT
    10126  1992-11-30 11:31   X-Mas Lemmings 1992/CLOSING.EXE
     1056  1991-12-03 10:08   X-Mas Lemmings 1992/GROUND2O.DAT
       28  1992-10-29 15:04   X-Mas Lemmings 1992/HELP.BAT
      492  1991-07-24 14:00   X-Mas Lemmings 1992/INSTALL.BAT
      763  1992-10-29 15:03   X-Mas Lemmings 1992/LEMMINGS.BAT
     2201  1992-11-25 11:55   X-Mas Lemmings 1992/LEVEL000.DAT
    59992  1991-12-03 15:24   X-Mas Lemmings 1992/MAIN.DAT
    16153  1991-12-03 14:51   X-Mas Lemmings 1992/MENU.EXE
     8733  1992-11-30 11:29   X-Mas Lemmings 1992/OPENING.EXE
     3560  1991-12-03 14:25   X-Mas Lemmings 1992/TANDYSND.DAT
    33123  1991-11-29 11:44   X-Mas Lemmings 1992/VGAGR2.DAT
    30469  1991-12-03 17:44   X-Mas Lemmings 1992/VGAL.EXE
       77  1992-11-30 11:36   X-Mas Lemmings 1992/VGALEMMI.BAT
---------                     -------
   778598                     67 files

All I want to extract is the folder with 1992 in the name to a folder named 1992/:

terrance@terrance-ubuntu:/media/500GB$ unzip -j Holiday\ Lemmings\ Pack.zip '*1992/*' -d '1992/'
Archive:  Holiday Lemmings Pack.zip
  inflating: 1992/ADLIB.DAT          
  inflating: 1992/CLOSING.EXE        
  inflating: 1992/GROUND2O.DAT       
 extracting: 1992/HELP.BAT           
  inflating: 1992/INSTALL.BAT        
  inflating: 1992/LEMMINGS.BAT       
  inflating: 1992/LEVEL000.DAT       
  inflating: 1992/MAIN.DAT           
  inflating: 1992/MENU.EXE           
  inflating: 1992/OPENING.EXE        
  inflating: 1992/TANDYSND.DAT       
  inflating: 1992/VGAGR2.DAT         
  inflating: 1992/VGAL.EXE           
  inflating: 1992/VGALEMMI.BAT       
terrance@terrance-ubuntu:/media/500GB$ cd 1992/
terrance@terrance-ubuntu:/media/500GB/1992$ ls
ADLIB.DAT     HELP.BAT      LEVEL000.DAT  OPENING.EXE   VGALEMMI.BAT
CLOSING.EXE   INSTALL.BAT   MAIN.DAT      TANDYSND.DAT  VGAL.EXE
GROUND2O.DAT  LEMMINGS.BAT  MENU.EXE      VGAGR2.DAT
  • This is a great answer. – Pilot6 Jun 6 '18 at 15:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.