LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Delete every other file from zip file. (https://www.linuxquestions.org/questions/linux-newbie-8/delete-every-other-file-from-zip-file-4175717715/)

junomario 10-13-2022 09:10 AM

Delete every other file from zip file.
 
How I can delete every alternate file from a zip file(1st,3rd,5th....) with command without unziping zip file.

I also want this operation on multiple zip files.

Thanks.

business_kid 10-13-2022 09:18 AM

You can't.

teckk 10-13-2022 09:20 AM

I doubt if you can. And, doesn't serve much purpose. If you want to edit a zip file.
You could extract the files to temp, edit the files, then rezip.

https://superuser.com/questions/6476...tly-extracting
https://www.geeksforgeeks.org/zip-co...with-examples/

michaelk 10-13-2022 09:43 AM

You can by writing a bash script.

1. Create a file with just the file names using the zipinfo utility.
2. Use a while loop to iterate through the list and delete the desired file using the zip -d option.

There are many ways to expand the script to work on multiple zip files but not enough information has been provided.

business_kid 10-14-2022 04:02 AM

You can't do what was suggested in post #1 because there's no way of deleting part of an archive, so the zips would have the deleted files anyhow.

All explopde --> delete --> re-zip solutions are good, but more processor intensive.

lvm_ 10-14-2022 04:55 AM

Something like this

zipinfo -1 q.zip|while read f;do read f;echo $f;done|zip -d -@ q.zip

boughtonp 10-14-2022 08:56 AM


 
Just to make this absolutely clear:

Yes, you can delete from ZIP files without decompressing the entire archive.

You can't do it with a TGZ archive, because the files are concatenated into a single lump of data before compression, but ZIP files do not work the same way.

This means ZIP archives tend to have less compression, but provides the benefits of being able to view/extract an individual file without decompressing other files, as well as being able to add/update/remove files without recompressing the whole archive.

Some archive formats (e.g. RAR) give you a choice of whether to use solid compression or not.


mrmazda 10-14-2022 06:12 PM

Quote:

Originally Posted by boughtonp (Post 6386343)
Just to make this absolutely clear:
Yes, you can delete from ZIP files without decompressing the entire archive.

I do it often, though I'm not sure whether the zip is technically fully decompressed or not in the process. It's very simple. Open a terminal or login on a vtty. Type mc. Press <RETURN>. If this returns a not found error, install mc and try again. Mc should be a part of every sensible installation, and may be in your main apps menu. Once mc is running, navigate to the zip file, then press <RETURN>. Then, mark using the INS key, or your mouse, the files you wish deleted. Press F8 or click 8Delete (at the bottom). Exit mc and poof, they're history.

This smells like another homework problem. :p


All times are GMT -5. The time now is 07:08 AM.