M06H
M06H

Reputation: 1783

Zip multiple directories into one zip file

 $ cat /home/myapp/properties.csv   
/document/source/
/downloads/lib/
/home/app/newFiles/

The above is a simple file that holds all the directories I'm interested in...

$ cat /home/myapp/zipup.sh
#!/bin/bash

folder="/home/myapp/properties.csv"
cat $folder| while read dir;

//zip all the directories read in

How do I complete zipup.sh script so that all directories and contents in each of the directories defined in the properties file are included in a single zip file i.e. the result should be something like this...

/result.zip     (everything goes in here)
   /source            
     /hello.class
     /hello.jar
   /lib  
     /xml.jar      
   /newFiles
     /list.doc

Upvotes: 0

Views: 2289

Answers (2)

nnair900
nnair900

Reputation: 95

#!/bin/bash

while read dir; do
zip result.zip $dir;
done < /home/myapp/properties.csv 

The zip command will add new entries to the same zipfile.

Please note that zip will overwrite entries with the same name.

Upvotes: 0

ILostMySpoon
ILostMySpoon

Reputation: 2409

#!/bin/bash

while read dir; do
    dirs="$dirs $dir"
done < /home/myapp/properties.csv

zip -r result $dirs

Upvotes: 1

Related Questions