Search code examples
bashshellunixzip

How to zip files without the top level folder but keep the sub folders


Suppose I have a folder named abc, it has several sub folders recursively, I want to zip everything under abc, when I use the following command

zip -r abc.zip abc/*

I get abc.zip, but it contains the top level folder abc, and everything is under abc, like abc/xxx, abc/yyy etc, How can I remove the top level folder abc? I want to put everything directly in abc.zip.

Note:

  1. I can only zip from outside of the folder, so navigate to folder abc, and zip * is not work for me
  2. I need to run this command in a single line, I can separated multiple commands by ;
  3. option -j also does not work, since it remove the sub folders, I want to keep them there.

Solution

  • cd abc
    zip -r ../abc.zip *

    Though I will say in most cases keeping it abc makes for easier management.