I'm trying to add unzipped files to an existing already zipped folder say
new folder.zip. Is it possible to use
zip -r new folder.zip after adding some unzipped files to them? Will this command compress the folder? Is there any alternative to do this?
Use the update flag:
zip -ur existing.zip myFolder
This command will compress and add
myFolder (and it's contents) to the
The update flag actually compares the incoming files against the existing ones and will either add new files, or update existing ones.
Therefore, if you want to add/update a specific subdirectory within the zip file, just update the source as desired, and then re-zip the entire source with the
-u flag. Only the changed files will be zipped.
If you don't have access to the source files, you can unzip the zip file, then update the desired files, and then re-zip with the
-u flag. Again, only the changed files will be zipped.
Original Source Structure
ParentDir ├── file1.txt ├── file2.txt ├── ChildDir │ ├── file3.txt │ ├── Logs │ │ ├── logs1.txt │ │ ├── logs2.txt │ │ ├── logs3.txt
Updated Source Structure
ParentDir ├── file1.txt ├── file2.txt ├── ChildDir │ ├── file3.txt │ ├── Logs │ │ ├── logs1.txt │ │ ├── logs2.txt │ │ ├── logs3.txt │ │ ├── logs4.txt <-- NEW FILE
$ zip -ur existing.zip ParentDir > updating: ParentDir/ChildDir/Logs (stored 0%) > adding: ParentDir/ChildDir/Logs/logs4.txt (stored 96%)
I believe you can add files using this command:
zip -r zipfile.zip newfile.txt newfile1.txt
-r option of the zip command allows you to adding files.
The -u flag works for files to
zip -ur zip_to_upload.zip file_to_add.txt
I used with success the
zip command. with the grow (-g) option, in order to add a subfolder
folder1/folder2 containing the files
zip -gr folder.zip folder1/folder2
-r means recurse dir.
From my understanding -g should grow the zip files, not creating a new zip file (that may be useful with very large zip archives). In case of issues you can try first to create subfolders in folder.zip with (e.g.):
zip -g folder.zip folder1 zip -g folder.zip folder2
If you have lots of file in the same place with your zip archive and you want to copy all of them into the archive, you can do:
zip -ur zipfile.zip !(zipfile.zip)
This updates your zip file( the
-u option) recursively (
-r option) with all the files found except the zip file itself (
! is the negation of the zipfile)
Then, you can simply delete all the files except the zip file following the same rule above: