0

When I run the command zip arch.zip *, intending to add only the files in the pwd and none of its subdirectories, I instead get an archive containing all the files and all the subdirectories of the pwd although inside the archive the added subdirectories do not have any files in them. Clearly -r would be used to populate those subdirectories, but how do I prevent the empty subdirectories from being added to the archive at all?

Please note that the command is being run from a Bash script and I can not simply exclude any subdirectories by name because I won't know in advance which subdirectories will be present.

Surely I don't have to write a routine in the script to loop through the directory's files, individually adding them based on their file type?

1

Use the -D option:

zip -D arch.zip *

This tells zip not to create entries for directories.

  • 1
    Thanks. That'll teach me to search the man more accurately, using subdir as the search term failed me. – mattst Aug 11 '16 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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