Possible Duplicate:
Build Zip archive, special cases

I'm using zip to archive different files. I need to create a directory in the zip file where to place some of them. Is that possible ?

The syntax I got so far is
zip output.zip -r /var/www/test

Inside the zip I want a folder called backup1 and in there the files from /test.

link|improve this question

25% accept rate
Might this be better suited to ServerFault? It seems more like a sysadmin question than a programming question to me. – ssokolow Nov 29 '10 at 20:54
feedback

migrated from stackoverflow.com Nov 29 '10 at 23:30

This question came from our site for professional and enthusiast programmers.

closed as exact duplicate by Arjan, Randolph West, Gilles, random Nov 30 '10 at 2:36

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

2 Answers

Why don't you just make the directory structure you want and then zip it and then remove it?

cd ~/
mkdir backup1
cp /var/www/test/* backup1/
zip -r output.zip ~/backup1
rm -r backup1
link|improve this answer
Because I'm used to command line flexibility and I thought I'm missing something. Good tip though. – user56301 Nov 29 '10 at 16:48
man zip doesn't seem to allow you to create directories. If you want to do in one line; just cp /var/www/test/* backup1/ && zip -rm output.zip backup1/ (m for move the files) part is to not have to have feature-bloat; there's no real reason to let zip create files/dirs that don't exist, when you can do it perfectly fine with other commands. – jimbob Nov 29 '10 at 16:56
feedback

$ ln -s /var/www/test backup1
$ zip -r backup1 -j backup1/*

Acceptable?

link|improve this answer
You are junking the directories and create a new sim link in the process.. I don't think it's optimal. Thanks anyways. – user56301 Nov 29 '10 at 16:55
feedback

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