Hugoagogo
Hugoagogo

Reputation: 1646

Batch script to move files into a zip

Is anybody able to point me in the right direction for writing a batch script for a UNIX shell to move files into a zip one at at time and then delete the original.

I cant use the standard zip function because i don't have enough space to fit the zip being created.

So any suggestions please

Upvotes: 3

Views: 6229

Answers (4)

Hicham
Hicham

Reputation: 81

I use :

zip --move destination.zip src_file1 src_file2

Here the detail of "--move" option from the man pages

--move

Move the specified files into the zip archive; actually, this deletes the target directories/files after making the specified zip archive. If a directory becomes empty after removal of the files, the directory is also removed. No deletions are done until zip has created the archive without error. This is useful for conserving disk space, but is potentially dangerous so it is recommended to use it in combination with -T to test the archive before removing all input files.

Upvotes: 0

rhomu
rhomu

Reputation: 326

You can achieve this using find as

find . -type f -print0 | xargs -0 -n1 zip -m archive

This will move every file into the zip preserving the directory structure. You are then left with empty directories that you can easily remove. Moreover using find gives you a lot of freedom on what files you want to compress.

Upvotes: 0

Hugoagogo
Hugoagogo

Reputation: 1646

Not a great solution but simple, i ended up finding a python script that recursively zips a folder and just added a line to delete the file after it is added to the zip

Upvotes: 1

Femi
Femi

Reputation: 64700

Try this:

zip -r -m source.zip *

Upvotes: 3

Related Questions