LinuxQuestions.org
Review your favorite Linux distribution.
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-08-2018, 02:04 AM   #1
thomwblair
LQ Newbie
 
Registered: Oct 2018
Location: Richmond, VA USA
Posts: 9

Rep: Reputation: Disabled
How can I have zip -d file.zip "__MACOSX*" work on all zip files in directory?


I have a lot of zip files that contain __MACOSX files and I read that
Code:
zip -d file.zip "__MACOSX*"
will delete those files from file.zip.

However, that syntax will only work on one file (file.zip) at a time. I'd like instead to have the command work on all zip files in that directory. I tried
Code:
zip -d “*.zip” "__MACOSX*"
but that only gave me an error. I also tried
Code:
zip -d *.zip "__MACOSX*"
but that only deletes the files from the first zip file in the directory.

What syntax would make it delete all the unwanted files from all zip files in the directory?

Thanks in advance!
 
Old 10-08-2018, 08:49 AM   #2
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,272

Rep: Reputation: 216Reputation: 216Reputation: 216
Code:
for file in *.zip
do
zip -d $file "__MACOSX*"
done
 
2 members found this post helpful.
Old 10-08-2018, 09:10 AM   #3
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 852

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by RandomTroll View Post
Code:
for file in *.zip
do
zip -d $file "__MACOSX*"
done
"$file" is safer (in case of any risky character in the filename after substitution for example)

Last edited by l0f4r0; 10-08-2018 at 09:17 AM.
 
1 members found this post helpful.
Old 10-08-2018, 09:20 AM   #4
thomwblair
LQ Newbie
 
Registered: Oct 2018
Location: Richmond, VA USA
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by RandomTroll View Post
Code:
for file in *.zip
do
zip -d $file "__MACOSX*"
done
First, as a newbie, I'd like to thank you very much RandomTroll for trying to help me. I really appreciate the help.

Unfortunately though, it didn't work. Perhaps I'm misunderstanding what you're saying to do. I typed
Code:
zip -d $file "__MACOSX*"
while in my directory that has all the zip files that have all the __MACOSX files in them, but I got this error:
Code:
zip warning: __MACOSX*.zip not found or empty
zip error: Nothing to do! (__MACOSX*.zip)
So, either I misunderstood what you were telling me to do, or perhaps I was not clear enough in describing what I need to do. If I misunderstood, can you please clarify?

If I was not clear enough, here is a clearer description: I have a directory called CleanZip and in that directory are 4 zip files that I am using as test files:
Code:
[B-18] Minions.zip		
[B-18] Small power cell.zip
[B-18] Small Comms Console.zip	
[B-18] Sun Lights.zip
In reality, though, I have over a dozen more zip files just like these, with names like these, that I'd like to process. Each zip file contains many files that start with __MACOSX. Here are some examples:
Code:
        0  08-27-2018 23:00   __MACOSX/
        0  08-27-2018 23:00   __MACOSX/Sun Lights/
      120  08-27-2018 20:21   __MACOSX/Sun Lights/._.DS_Store
So, I'm wanting to delete all the __MACOSX files from all four zip files with one command. What would be the exact syntax to do that?

Last edited by thomwblair; 10-08-2018 at 09:29 AM.
 
Old 10-08-2018, 09:24 AM   #5
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 852

Rep: Reputation: 286Reputation: 286Reputation: 286
In CleanZip directory, did you type:
Code:
for file in *.zip
do
zip -d "$file" "__MACOSX*"
done
as RandomTroll explained?
...because you seem to have only entered the following:
Code:
zip -d $file "__MACOSX*"
EDIT:
try instead:
Code:
for file in *.zip
do
zip -d "$file" "__MACOSX\*"
done
It's safer to prevent * bash pre-expansion in order to let zip do it by itself

Last edited by l0f4r0; 10-08-2018 at 09:29 AM.
 
Old 10-08-2018, 09:26 AM   #6
thomwblair
LQ Newbie
 
Registered: Oct 2018
Location: Richmond, VA USA
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by l0f4r0 View Post
"$file" is safer (in case of any risky character in the filename after substitution for example)
Hi! Thank you for your reply! I tried:
Code:
zip -d "$file" "__MACOSX*"
but I got this error:
Code:
zip warning: .zip not found or empty
zip warning: name not matched: __MACOSX*
zip error: Nothing to do! (.zip)
I'm not sure if I'm misunderstanding what to do, or if I didn't describe my problem clearly enough. If I wasn't clear enough, I posted more details above in my reply to RandomTroll.

Thank you for your help though, I really appreciate it!
 
Old 10-08-2018, 09:30 AM   #7
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 852

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by thomwblair View Post
I tried...
See post #5 please
 
Old 10-08-2018, 09:36 AM   #8
thomwblair
LQ Newbie
 
Registered: Oct 2018
Location: Richmond, VA USA
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by l0f4r0 View Post
In CleanZip directory, did you type:
Code:
for file in *.zip
do
zip -d "$file" "__MACOSX*"
done
as RandomTroll explained?
...because you seem to have only entered the following:
Code:
zip -d $file "__MACOSX*"
Omg! I thought RamdomTroll was mistakenly enclosing the entire reply in CODE tags! I'm too new to realize that whole thing was proper syntax. Thank you! When I used all four lines of commands, it did work. Thank you!
Quote:
EDIT:
try instead:
Code:
for file in *.zip
do
zip -d "$file" "__MACOSX\*"
done
It's safer to prevent * bash pre-expansion in order to let zip do it by itself
Thank you! I will try that too. Thanks again!

Last edited by thomwblair; 10-08-2018 at 09:39 AM.
 
Old 10-08-2018, 09:40 AM   #9
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 852

Rep: Reputation: 286Reputation: 286Reputation: 286
You're welcome but all credit goes to RandomTroll
Can you mark your thread as "solved"?
 
Old 10-08-2018, 10:37 AM   #10
thomwblair
LQ Newbie
 
Registered: Oct 2018
Location: Richmond, VA USA
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by l0f4r0 View Post
You're welcome but all credit goes to RandomTroll
Can you mark your thread as "solved"?
Thank you, I just discovered I can do that.
 
Old 10-08-2018, 02:30 PM   #11
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Can be fixed after the fact by
Code:
zip -d filename.zip __MACOSX/\*
says https://superuser.com/questions/1045...-macosx-folder
 
  


Reply


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
Using zip to zip the contents of a directory to another? Paradigm6790 Linux - Newbie 2 07-25-2012 11:51 AM
Linux zip program's -d -tt option deletes all files from zip archive Arun Gupta Linux - Software 4 04-27-2011 07:06 PM
uncompress .zip with "tar -ixz Filename.zip" , can it be done ??? htetnaing Linux - Newbie 2 08-17-2008 05:10 AM
Zip gives error "-bash: /usr/bin/zip: Argument list too long" konathamsrinu Programming 3 07-06-2006 10:08 AM
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 10:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration