Unzip file contents, but without creating archive folder

cpzip

I have a file myarchive.zip that contains many directories, files, etc. Let's say this myarchive.zip file lives in a directory called "b". Well, when I use the "unzip myarchive.zip" command, the system creates a directory by default called "myarchive" with the contents of the zip file. I do not want the system to create this "myarchive" directory – I just want the contents to be extracted to directory "b". Is this possible?

What I've been doing now is simply issuing a "cp" command to copy the files from the newly created directory (in this case "myarchive" to "b") to where I want them.

Best Answer

My version of unzip has a -j option to not create any directory.

So

unzip -j /path/to/file.zip

Will extract all the files into the current directory without restoring the directory structure stored in the zip file.

If you want to only remove one level of directories from the archive, (extract myarchive/dir/file as dir/file, not file), you could use bsdtar (which does supports zip files in addition to tar files) instead and its -s option.

bsdtar -xf /path/to/file.zip -s'|[^/]*/||'
Related Question