3

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

2 Answers 2

1

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
1
  • 1
    this flatten the directory structure, everything will be in the root directory Sep 12, 2016 at 14:47
1

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

You must log in to answer this question.

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