Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

zip
|-folder
  |--files
  |--files

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

zip
|-files
|-files

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

share|improve this question
add comment

3 Answers

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
add comment

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 –  Gramps Dec 19 '12 at 17:23
add comment
up vote 0 down vote accepted

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
add comment

Your Answer

 
discard

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.