6

I have the following folder structure

folder
|
|--foo.txt
|
|--sub_folder
   |
   |--bar.txt

I want to zip the content (files and sub folders) of folder without including the root folder in the zip.

I have tried command

zip -r package.zip folder

But this includes the root folder. Also tried the following form

zip -j -r package.zip folder

But this will flatten all the directory structures and just include the files. How do I preserve the internal directory structure but ignore the parent folder?

11

zip stores paths relative to the current directory (when it is invoked), so you need to change that:

(cd folder; zip -r ../package.zip .)

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.