1

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.

muru
  • 72,889

2 Answers2

2

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 08: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
0

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:

https://stackoverflow.com/questions/20529851/zip-command-not-working

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