Macos – Unzip a file into a target directory

macoszip

I have a file called All CRGs.zip and I want to unzip its contents into a directory called data (which already exists and has some other files in).

Is this possible? I'm working on OSX.

I've tried:

$ unzip "All CRGs.zip" -d data/

But this unzips everything into data/All CRGs which is not what I'm looking for. I'd like everything to go straight into data.

Is this possible?

Best Answer

You can either recreate the complete folder-structure including the All CRGs-Folder or you can ommit all folders inside the ZIP-file by using the -j-flag for the unzip-command.

The problem is that the ZIP-file has been created using the All CRGs-Folder as top-level like zip "All CRGs.zip" "All CRGs". The correct way would have been zip "All CRGs.zip" "All CRGs/*"which would have created a ZIP-Archive of all the files and folders inside the All CRGs-folder without the surrounding folder.

So the only way to extract only the files by retaining the folder-structure would be something like this:

unzip "All CRGs.zip" -d data/ && mv "data/All CRGs/*" "data/" && rmdir "data/All CRGs"

It will unzip the complete folder and after that move the content of the folder up one level and finaly remove the (now empty) "All CRGs"-folder.