Directory – Zip All Files and Subfolders Without Parent Directory

directoryfilenameszip

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?

Best Answer

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

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