Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.