I have a ZIP file in which there is a top directory where all the files are stored:


I want to extract everything under Release, preserving the directory structure, but when I run this:

unzip archive.zip Release/* -d /tmp

It creates the top Release folder:


How I can extract everything inside Release without creating a Release folder, like this:

  • Try this unzip archive.zip && mv Release/* . – George Udosen Mar 12 '17 at 0:48
  • @George this still creates a Release folder – jsta Jun 8 '17 at 17:47

In your case, try in target folder:

ln -s Release . && unzip <YourArchive>.zip

Than you need to remove the link you've created:

rm Release
  • 1
    The order of parameters for ln is swapped. It should be ln -s . Release. – Ulf Adams May 1 '20 at 13:12

The j flag should prevent folder creation unzip -j archive.zip -d .

From the man page:


junk paths. The archive's directory structure is not recreated; 
all files are deposited in the extraction directory (by default, the
current one).
  • 11
    I think this is close, but the OP was looking to only skip creation of the top level directory and preserve the remaining directory structure. the -j option dumps all files into the current directory without regard to the directory structure in the archive. – Charles Green Jun 8 '17 at 19:00

Python script for flattening extracted tree

The script written bellow extracts zip file and moves files contained within topmost directory out of it to the current working directory. This quick script is tailored to suit this particular question where there is one single topmost directory that contains all the files, although with a few edits can be made suitable for more general cases.

#!/usr/bin/env python3
import sys
import os
from zipfile import PyZipFile
for zip_file in sys.argv[1:]:
    pzf = PyZipFile(zip_file)
    top_dir = namelist[0]
    for item in namelist[1:]:
        rename_args = [item,os.path.basename(item)]

Test run

Here's an example of how the script is supposed to work. Everything extracted to current working directory, but source file can be in differet directory altogether. The test is performed on the zip archive of my personal github repository.

$ ls                                                                                   
flatten_zip.py*  master.zip
$ ./flatten_zip.py master.zip                                                          
['utc-time-indicator-master/.gitignore', '.gitignore']
['utc-time-indicator-master/LICENSE', 'LICENSE']
['utc-time-indicator-master/utc-time-indicator', 'utc-time-indicator']
['utc-time-indicator-master/utc_indicator.png', 'utc_indicator.png']
$ ls
flatten_zip.py*  LICENSE  master.zip  utc_indicator.png  utc-time-indicator

Test with source file being in different location

$ mkdir test_unzip
$ cd test_unzip
$ ../flatten_zip.py  ../master.zip                                                     
['utc-time-indicator-master/.gitignore', '.gitignore']
['utc-time-indicator-master/LICENSE', 'LICENSE']
['utc-time-indicator-master/utc-time-indicator', 'utc-time-indicator']
['utc-time-indicator-master/utc_indicator.png', 'utc_indicator.png']
$ ls
LICENSE  utc_indicator.png  utc-time-indicator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy