I am unzipping the .zip file. I'm able to do so but my requirement to extract only the parent folder data ignoring any sub directory and their contents.
Below is the name format of zip file.
filename.csv.zip
commands I have used unzip -j /zip_filepath "*" -d /final_directory.
I tried with above commands but above commands extracting all the complete zip contents which are the part of zip file.
Please find below the file structure of zip file.
- -rw-r--r-- abc.csv
- drwxrwxr_x __MACOSX/
- -rw-r--r-- __MACOSX/_abc.csv
Second zip file structure: *-rw-r--r-- xyz.csv
I want to extract only abc.csv and xyz.csv files from the zip files.
Output of: unzip -Z -1 abc.zip
__MACOSX/
__MACOSX/_abc.csv
abc.csv
Output:unzip -Z -1 /user/sam/abc.zip -d /user/sam/2019-05-22/
caution: not extracting -d ignored
abc.csv
__MACOSX
__MACOSX/._abc.csv
The output here should be abc.csv file only
Output of: unzip -Z -1 xyz.zip
xyz.csv
Output:unzip -Z -1 /user/sam/xyz.zip -d /user/sam/2019-05-22/
caution: not extracting -d ignored
xyz.csv
This edit will be visible only to you until it is peer reviewed
... If you don't see it, wait for a while, and check again later.unzip -Z -1 abc.zip
andunzip -Z -1 xyz.zip
) are just for listing, not for extracting. The idea of those command, is that can give us a way to know that we're talking about the same directory structure... When using those commands, remove the-d /user/sam/2019-05-22/
... on the other hand, the command for extraction is the one on my answer:unzip filename.csv.zip -x '*/*' -d /final_directory
, and I think is the correct command for both situations, if the structure is what you post. If is not working... Are you getting some specific error?