Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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