6

I'm trying to zip a directory a linux using the following command:

zip -r file.zip .

This works, but it isn't include the empty directories that I want to be included in the zip file. How can I get them to be included?

2 Answers 2

6

The answer you're most likely looking for is:

zip -r file.zip . -i \*

You get a warning when zipping an empty folder but again the solution is size-agnostic for its function. It works for empty and non-empty directories.

This solution works in the relative sense unlike solutions that use $PWD such as

zip -r file.zip $PWD

which will compress the whole folder structure.

1
  • cat you explain why this works? Commented Jul 14, 2020 at 0:31
4

What version of zip are you using? I've got:

$ zip -v
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.

And if I create some directories:

$ mkdir -p a/{b1,b2}

And then create a zip file:

$ zip -r file.zip .
adding: a/ (stored 0%)
adding: a/b1/ (stored 0%)
adding: a/b2/ (stored 0%)

The resulting archive appears to have the empty directories:

$ unzip -l file.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  01-11-2011 11:54   a/
        0  01-11-2011 11:55   a/b1/
        0  01-11-2011 11:54   a/b2/
---------                     -------
        0                     3 files

You must log in to answer this question.

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