This question already has an answer here:

I'm new to using the terminal and I found a post on here with the following code that would allow me to zip multiple directories into individual zip files but I only got it to work once. The code is this:

for i in */; do zip ‐r "${i%/}.zip" "$i"; done

but now when ever I use it I get the following error:

zip warning: name not matched:

and when I check the folder it creates a -r.zip file.

marked as duplicate by Anthon, cuonglm, dr01, Jeff Schaller, Jakuje Feb 20 '16 at 13:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Your command doesn't do zip -r but actually zip M-bM-^@M-^Pr that's why it doesn't work. – don_crissti Feb 20 '16 at 11:45

Seems like zip wants the zip file first:

for i in */; do zip "${i%/}.zip" -r "$i" ; done
  • I modded you up; please try to explain why you enclosed $i in {} for the benefit of the OP – Rui F Ribeiro Feb 20 '16 at 8:50
  • @RuiFRibeiro That is explained in the answer to the duplicate question here – Anthon Feb 20 '16 at 11:30
  • 3
    @Anthon - the problem here is that OP's command contains non-printable characters and that's why it doesn't work. Copy/paste the command in the OPs post and pipe it to cat -v... So I don't think it's a duplicate of that one (but should be closed nonetheless as a dupe of other questions that deal with this kind of stuff). – don_crissti Feb 20 '16 at 11:45
  • @Anthon The problem about botched copy&pastes is very common here indeed. – Rui F Ribeiro Feb 20 '16 at 12:44

If you're new to the terminal, then it's likely you haven't learned the daunting but helpful world of man pages :D

If you do man zip at the command line the intended usage of zip is the following:

"Normally when an input pattern
              does not match a file the "name not matched" warning  is  issued

If zip is not able to read a file, it issues a warning  but  continues.
       See  the -MM option below for more on how zip handles patterns that are
       not matched and files that  are  not  readable.   If  some  files  were
       skipped, a warning is issued at the end of the zip operation noting how
       many files were read and how many skipped."

I would start by replacing your zip command with a an echo "${i%/}" and see what your output is. Somewhere a folder is causing an issue, either you are unable to access it or it's name is incorrect. Since you're just looking at folders in one directory you can use find . -type d -readable to compare against the directories you want to access to see if there is a folder that you do not actually have access to read.

related Unix Stack Exchange Answers:


"zip warning: name not matched" while compressing a directory

Not the answer you're looking for? Browse other questions tagged or ask your own question.