3

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?

2

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).

0

zip -rj $folder $folder

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

  • that works but deletes any folders that may exist. I'm trying to only prevent the main folder from being duplicated – DᴀʀᴛʜVᴀᴅᴇʀ Dec 19 '12 at 17:23
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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