Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Im trying to extract the contents of a zip file but I want to extract it to my own directory.
I'v tried -d from unzip but that just puts the contents of the zip into that directory.

But I want to extract the contents of the first (root) directory in the zip if there is only one directory in the root of the zip else just extract the files/folders in the root of the zip file (if there are more then one files).

e.g. test.zip contents the following dir structure:

test.zip
  \
 /app_v1/ <-The contents of this directory I want extracted to a dir of my choice
      \
     - folder-1
     - folder-2
     - folder-3
     - folder-4
     - file1
     - file2
share|improve this question

migrated from stackoverflow.com Apr 21 '11 at 21:37

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

You probably want to combine -j with -d. -j lets you junk the paths that are there. Mind you, if there're other folders you don't want, they'll get lumped in too.

unzip -jd <some_path> test.zip
share|improve this answer

or you can use the most flexible

unzip -p zipfile.zip some/path/file.txt > otherfilename.txt

This way you can even immediately do whatever it was you wanted to with it without having to save it, if that's only a temporary file, e.g.

unzip -p zipfile.zip some/path/file.iso | md5sum
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .