Initial situation:
.
├── d0
├── f0
├── f1
│ └── d1
└── f2
└── f3
├── d2
├── d3
└── d4
What I need to do:
I would like to create a zip containing d0, d1 and d4 which must have the fallowing structure:
.
├── d0
├── d1
└── d4
What I have already tried:
I tried it with zip myfiles d0 f1/d1 f2/f3/d4
. But this keeps the original folder structure, which is not what I want.
.
├── d0
├── f1
│ └── d1
└── f2
└── f3
└── d4
Question How to create a zip with multiple files without the sub-folders?
You can use
find
to get the file list and executezip -j myfiles
to pack them ignoring the paths:Example
However this works for files only, directories will be ignored by
zip -j
. To get this working for directories too, say we want to packd0
,d1
and the wholef3
directory in the above example, thefind
line gets a little more complicated:Manually, you can create the zip file and the update it:
The parentheses create subshells, and the effect of the
cd
only lasts in the subshell, so you don't have tocd
back to the original directory.If
d1
,d2
, etc. are actually files and not directories themselves, then use the-j
option:Using the -j option will remove the path from the file.
reference