You can either recreate the complete folder structure including the All CRGs folder or you can omit all folders inside the ZIP file by using the -j-flag for the unzip command.
The problem is that the ZIP file was 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 finally remove the (now empty) "All CRGs" folder.
Answer from heiglandreas on Stack ExchangeYou can either recreate the complete folder structure including the All CRGs folder or you can omit all folders inside the ZIP file by using the -j-flag for the unzip command.
The problem is that the ZIP file was 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 finally remove the (now empty) "All CRGs" folder.
Since you know the zip file contains an unwanted top-level folder, and since you know the name of that top level folder, you can use a symlink to cause all the contents of that folder to appear in the parent like so:
ln -s . 'data/All CRGs'
unzip 'All CRGs.zip' -d data
The ln step causes the folder data/All CRGs to be created, linking to the current directory (relative to data/), which is data/. Then, when you extract files from All CRGs.zip and the unzip command tries to create data/All CRGs/file.dat, that file will get created as data/./file.dat.
This technique can be demonstrated without a zip file using touch:
$ mkdir data
$ ln -s . data/subdir
$ touch data/subdir/foo.txt
$ ls data
foo.txt subdir
You can use this trick too to cause certain files or folders to be extracted to an alternate folder:
ln -s /tmp data/subdir2
Then anything in the archive being extracted to subdir2 will appear in /tmp.
macos - Using the unzip command in SSH with Mac Terminal not working - Stack Overflow
What are all of the command line commands to unzip a file? I need one that preserves extended attributes.
How to unzip multiple parts in same folder with MacOS?
macos - Unzipping with Terminal Command - Stack Overflow
Does Mac have unzip?
How do I unzip a folder in Mac command line?
How do I unpack a tar GZ file on a Mac terminal?
Opposite of what virtually every fucking Google result says, I actually do need the __MACOSX folder that gets unzipped when using the normal "unzip" command from the terminal. I have some piece of shit software that I have to push out (ABA Secure Browser, if anyone has any hints), that comes prepackaged as a .app bundle in a .zip with lots of hidden extended attributes that totally break the app if they aren't there. Literally, nothing other than downloading, dragging, and dropping the app into Applications will result in a working app.
Google has been no help. Is there a simple command that I can use in a script to uncompress this .zip properly?