1

I am attempting to create a ZIP archive that contains 5 PDFs and one additional ZIP file (which resides in the folder above the current working folder). This seems to work, but only to a certain extent.

For example:

$ ls -lh
total 5.0M
-rw-r--r-- 1 root root 227K Apr  8 18:53 activity.pdf
-rw-r--r-- 1 root root 2.2M Apr  8 18:53 activity1.pdf
-rw-r--r-- 1 root root 279K Apr  8 18:53 activity2.pdf
-rw-r--r-- 1 root root 761K Apr  8 18:53 activity3.pdf
-rw-r--r-- 1 root root 1.6M Apr  8 18:53 activity4.pdf

$ ls -lh ..
total 11M
-rw-r--r--  1 root root  11M Apr  5 12:16 Another_Archive.zip

To zip the 5 PDF files and the ZIP that exists in the previous folder, I am doing the following:

$ zip Final_Archive.zip *.pdf ../Another_Archive.zip 
  adding: activity.pdf (deflated 12%)
  adding: activity1.pdf (deflated 10%)
  adding: activity2.pdf (deflated 11%)
  adding: activity3.pdf (deflated 9%)
  adding: activity4.pdf (deflated 11%)
  adding: ../Another_Archive.zip (stored 0%)

Now whenever I run unzip from the CLI, I can see everything properly:

$ unzip Final_Archive.zip
Archive:  Final_Archive.zip
  inflating: activity.pdf
  inflating: activity1.pdf
  inflating: activity2.pdf
  inflating: activity3.pdf
  inflating: activity4.pdf
warning:  skipped "../" path component(s) in ../Another_Archive.zip
 extracting: Another_Archive.zip

$ ls -lh
total 31M
-rw-r--r-- 1 root root  11M Apr  5 12:16 Another_Archive.zip
-rw-r--r-- 1 root root  15M Apr  8 19:02 Final_Archive.zip
-rw-r--r-- 1 root root 227K Apr  8 18:53 activity.pdf
-rw-r--r-- 1 root root 2.2M Apr  8 18:53 activity1.pdf
-rw-r--r-- 1 root root 279K Apr  8 18:53 activity2.pdf
-rw-r--r-- 1 root root 761K Apr  8 18:53 activity3.pdf
-rw-r--r-- 1 root root 1.6M Apr  8 18:53 activity4.pdf

However, if I unzip the file from Mac OS (just double clicking on the zip file), it extracts everything but the Another_Archive.zip file. See below:

enter image description here

If I unzip it from MacOS from the CLI, it works perfectly fine. Is this due to some sort of issue with the unarchiving process on MacOS, or an issue with the way the zip file is being created?

2
  • You're putting ../Another_Archive.zip into the archive, with the ../ path. In Finder, does Another_Archive.zip get extracted into the parent directory? Commented Apr 8, 2022 at 19:16
  • Nope. Doesn't extract Another_Archive.zip into the parent directory. Commented Apr 8, 2022 at 19:49

1 Answer 1

1

I imagine Finder is refusing to extract files into a parent folder from the one you are working in, because that doesn't match user expectations and could be dangerous (clobbering files you thought were safe.)

So don't include paths to parent folders in the zip file.

You can make a symlink to the zip in the same folder with the PDFs:

ln -s ../Another_Archive.zip .
zip Final_Archive.zip *.pdf Another_Archive.zip

Alternatively, you could pack the PDFs into the zip, then add the archive to it.

zip Final_Archive.zip *.pdf
cd ..
zip directory/Final_Archive.zip Another_Archive.zip

Or, if your zip has the -j option ("junk (don't record) directory names"), that will cause it to store the files without a directory path.

 zip -j Final_Archive.zip *.pdf ../Another_Archive.zip
1
  • Adding the -j parameter seems to have done the trick. Thanks! Commented Apr 8, 2022 at 20:11

You must log in to answer this question.

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