Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

If I zip a folder, make changes to the normal unzipped files and then zip that folder again, is it possible to have only those changed files in a new separate archive?

So first zip command would be:

zip -r folder.zip *

Second one something like:

zip -r -u folder.zip * < changedFilesOnly.zip // would save output
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Yes, it's possible to do this and there's a zip command switch specially designed for that purpose. I'll show you by way of an example, and then you can adapt it to your own purposes.

I first created a zip archive of my script folder with the following command (working from my home folder):

zip -r Scripts.zip Scripts

Now this had 76 items. I then added some 2 pdfs to the Scripts folder on disk and then ran the following command, and transferred just the new and changed files to a new zipfile:

zip -r Scripts.zip Scripts -DF --out new.zip

This was the output:

updating: Scripts/ (stored 0%)
adding: Scripts/GIMP+Magazine+Issue+1.pdf (deflated 2%)
adding: Scripts/Whitepaper-CentralisedLogging-v1.pdf (deflated 10%)

Now only these 2 new files are in new.zip, and they have not been added to the original zip. In the command, the -DF option allowed us to create a 'difference archive' specified with the --out switch, so that any new files present in the folder on disk, but not in the original zip, go to the new zip. So according to the man page, it is indeed possible to

create an archive that contains all new and changed files since the original archive was created. For this to work, the input file list and current directory must be the same as during the original zip operation.

There are some interesting options to play around with for zip, so please see man zip or the Ubuntu manpages online.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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