Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create a zip in a linux distro and
- keep only the relative path to a folder
- put some files in a separate folder inside the zip

I need to do this in a bash script so if i just use the absolute path the entire path will be inside the zip.

Example

/home/user/folder/1.txt
/home/user/folder/2.txt

Output Need It :

test.zip
folder/1.txt
folder/secondfolder/2.txt
share|improve this question
1  
How does the output relate to the example? – Ignacio Vazquez-Abrams Nov 29 '10 at 9:55
    
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
( cd /var/www ; zip -r - test1 ) > output.zip
share|improve this answer
    
this is correct regardless of duplicate +1 – RobotHumans Nov 29 '10 at 17:55

Does find . ! -name "*.zip" -type f -print | zip test -@ do what you want?

share|improve this answer
    
zip is capable of recursing a path on its own. – Ignacio Vazquez-Abrams Nov 29 '10 at 10:01
    
I updated the question. This is not what I need. – user56301 Nov 29 '10 at 10:23
    
@user, I updated the question -- adding "need it" is hardly an update! (Also, please come up with a better title?) – Arjan Nov 29 '10 at 12:10
    
@Ignacio and Charles, so maybe zip -r -x *.zip would achieve the same? – Arjan Nov 29 '10 at 12:30

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
share|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

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

Acceptable?

share|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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .