0

This question already has an answer here:

I want to create a ZIP archive of a directory without going into the directory itself, and not include that directory

Zip the contents of a folder without including the folder itself - This post guides to changed the current directory and then create the archive. But, as stated earlier, i do not want to change the current directory.

This is the structure of the directory that I want to archive

parentdir/
parentdir/dir1/
parentdir/dir1/file1.txt
parentdir/dir1/file2.txt
parentdir/dir2/
parentdir/dir2/file1.txt
parentdir/dir2/file2.txt

And the desired archive would contain

dir1/
dir1/file1.txt
dir1/file2.txt
dir2/
dir2/file1.txt
dir2/file2.txt

If I use the command

zip -r output.zip parentdir/

this includes the parentdir as well in the archive.

Is there any flag that allows us to create an archive without the parentdir ? I do not want to change the current directory to the parentdir. I cannot also use the -j flag,since I do not want to junk the rest of the paths. Can i accomplish this from any directory?

marked as duplicate by dhag, Anthon, chaos, jimmij, cuonglm Aug 14 '15 at 2:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    (1) Your constraint sounds arbitrary — like “I need to get dressed, but I don’t want to open the closet door (where my clothes are) or reach into the closet.”  If you explained the basis (reason) for your stipulation, (a) you might get more sympathy (and, consequently, more effort and more/better answers), and (b) it might turn out to be an XY Problem, and we might be able to solve your real issue.  (2) If not going into the directory itself is an essential part of the problem statement, you should probably mention it in the question title. – G-Man Aug 13 '15 at 18:43
5

I'm not aware of such a flag to zip. You say:

I do want to change the current directory to the parentdir

by which I assume you mean you do not want to change to the parentdir. Under that assumption, I would use:

(cd parentdir; zip -r ../output.zip .)
  • Sorry about that.. The intended phrase was "I do not want to change the current directory to the parentdir" . – Kenpachi Aug 13 '15 at 16:37

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