Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm learning zip and I have run into something I cannot figure out in man zip. When I run zip -r $folder $folder it will correctly zip all contents but the zip contents is as follows:


That is annoying to me and I wanted the zip outcome to be:


Suggestions on being able to create a zip file with the folder name and all contents?

share|improve this question
up vote 2 down vote accepted

Not directly through zip, but (cd test && zip -r ../test.zip *) should do.

Edit: I do not know of an option in zip which allows to the equivalent of tar -cf test.tar -C test . (which does exactly what you want).

share|improve this answer

zip -rj $folder $folder

Will remove directories when adding files to the archive. with info-zip.

share|improve this answer
that works but deletes any folders that may exist. I'm trying to only prevent the main folder from being duplicated – Darth_Vader Dec 19 '12 at 17:23

I realized what I forgot when I asked a friend. In the loop I had set a global variable for the location. In the for loop I forgot to add cd $folder before the zip process which caused it to zip the folder and the contents.

share|improve this answer

Your Answer


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.