I have a directory called folder that looks like this:

      -> root_folder
                    -> some files

I want to zip this directory into zipped_dir, I tried:

zip -r zipped_dir.zip folder/*

But this generates a ZIP that looks like this:

          -> folder
                   -> root_folder
                                 -> some files

in other words, it's including the directory whose contents I want to zip. How can I exclude this parent directory from the ZIP, without moving anything?

IE I would like this end result:

          -> root_folder
                        -> some files

Try to use this command (you will get the idea)

cd folder; zip -r ../zipped_dir.zip *

Maybe there is other way, but this is fastest and simplest for me :)

  • 2
    this works perfectly doing that trick. note: it will do a chroot . – loretoparisi Aug 25 '16 at 14:24
  • equivalent: zip -r zipped_dir.zip folder/* – Tobias Kolb Sep 12 '18 at 9:35
  • 5
    @TobiasKolb, maybe you do not read the question. OP do not want to have folder in to the stored path in zip. – Romeo Ninov Sep 12 '18 at 10:55
  • 2
    Seems the only way to do – Robert Sep 13 '18 at 2:32
  • 1
    @PabloDiaz, in my example cd - will do the work (only one command) :) Or cd .. – Romeo Ninov Feb 15 at 18:37

Use -j; for example: zip -r -j zipped_dir.zip folder/*

It won’t zip 'root_folder'.

  • 7
    I get an error with this one if I have two files of the same name. – Chris Dec 1 '16 at 22:06
  • 11
    OP probably wants only the parent directory removed, not all of them. – tokland Mar 13 '17 at 10:13
  • Still creates directories zip -r -j package.zip ./dist/static/* makes archive structure dist/static/myfiels – deathangel908 Jul 20 '17 at 15:25
  • 4
    it flatten's child directory files as well. – Sumit Ramteke May 10 '18 at 7:19
  • 3
    the -j option eliminate all directory info and only save files. That is, to store all files under one directory in a "flat" way. – Robert Sep 13 '18 at 2:34
zip -r -D zipped.zip *

-D instructs zip to not create directories.


This is what works for me:

7z a zipped.zip ./rootDir/*

It will create a zip archive with root: any files/directories inside rootDir.

protected by Community Nov 15 '17 at 22:56

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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