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
  • 7
    @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
  • 3
    Seems the only way to do – Robert Sep 13 '18 at 2:32
  • 1
    this won't add hidden files – Gus Nov 25 '18 at 0:53
  • 1
    @PabloDiaz, in my example cd - will do the work (only one command) :) Or cd .. – Romeo Ninov Feb 15 '19 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
  • 15
    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
  • 4
    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.

  • The best answer for me need. – Marcin Jan 1 at 2:27

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