LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-13-2022, 09:10 AM   #1
junomario
LQ Newbie
 
Registered: Mar 2021
Posts: 12

Rep: Reputation: Disabled
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.
 
Old 10-13-2022, 09:18 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,251

Rep: Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321
You can't.
 
Old 10-13-2022, 09:20 AM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,134
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
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/
 
Old 10-13-2022, 09:43 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,675

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
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.

Last edited by michaelk; 10-13-2022 at 09:44 AM.
 
Old 10-14-2022, 04:02 AM   #5
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,251

Rep: Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321Reputation: 2321
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.
 
Old 10-14-2022, 04:55 AM   #6
lvm_
Member
 
Registered: Jul 2020
Posts: 909

Rep: Reputation: 312Reputation: 312Reputation: 312Reputation: 312
Something like this

zipinfo -1 q.zip|while read f;do read f;echo $f;done|zip -d -@ q.zip
 
Old 10-14-2022, 08:56 AM   #7
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,596

Rep: Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545

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.

 
1 members found this post helpful.
Old 10-14-2022, 06:12 PM   #8
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,799
Blog Entries: 1

Rep: Reputation: 2066Reputation: 2066Reputation: 2066Reputation: 2066Reputation: 2066Reputation: 2066Reputation: 2066Reputation: 2066Reputation: 2066Reputation: 2066Reputation: 2066
Quote:
Originally Posted by boughtonp View Post
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.
 
  


Reply

Tags
archive, bash, command line, zip


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Backed up HD to tar., ZIP, g-zip file stuck on shell prompt thefinickyhobo Linux - Newbie 16 11-20-2019 06:22 AM
[SOLVED] How can I have zip -d file.zip "__MACOSX*" work on all zip files in directory? thomwblair Linux - Newbie 10 10-08-2018 02:30 PM
How to find out a file in a WAR which in a zip without unzip the zip-file? thomas2004ch Linux - Software 3 09-30-2011 03:06 PM
How to set up a Cron Job to run every other week or every three months etc. kckabobus Linux - Newbie 3 04-03-2008 01:36 PM
create a self-extracting zip file with zip on solaris? samsolaris Solaris / OpenSolaris 3 10-15-2004 01:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration