Home > Net >  Update file in subfolder of zip in linux / bash
Update file in subfolder of zip in linux / bash

Time:03-30

I am trying update my zip but there is constant problem like zip error: Nothing to do! or wrong path with subfolders.

Input: file to update /main/zip/folder_1/file1.xml

zip target: /main/zip_file1.zip -> but this zip include subfolders like ../sub1/file1.xml etc.

Expected result: update file1.xml in zip_file1.zip but in correct path like zip_file1.zip/sub1/file1.xml

how can I do it?

I was trying this:

zip -ur zip_file1.zip ./main/zip/folder_1/file1.xml

zip -ur zip_file1.zip '*/file1.xml' ./main/zip/folder_1/file1.xml

zip -ur zip_file1.zip '/sub1/file1.xml'./main/zip/folder_1/file1.xml

CodePudding user response:

It's not possible to make main/zip/folder_1/file1.xml be sub1/file1.xml in the zip archive, the paths must be identical.

A work-around is to recreate the trees and files that you want to update:

mkdir sub1
ln main/zip/folder_1/file1.xml sub1/
zip -rum zip_file1.zip sub1/

or

ln -s main/zip/folder_1/ sub1
zip -ru zip_file1.zip sub1/
rm -f sub1

Which one is the best depends on your context:

  • use the first code for updating only a few select files of main/zip/folder_1/

  • use the second code for updating all the files and directories in main/zip/folder_1/

  • Related