How can I automatically ZIP files with same file names (different extensions) into one ZIP?

For example I have four files

  • king.jpg
  • king.txt
  • queen.jpg
  • queen.txt

which would led to

  • king.zip (containing king.jpg and king.txt)
  • queen.zip (containing queen.jpg and queen.txt)

2 Answers 2


You can easily do this with a short bash snippet.

for i in *; do
    if [[ "$p" != "$f" ]]; then
        zip "$f" "$f".*

If you are not familiar with Terminal/bash and don't plan to use this too often, you can do the following to use it:

  • create a folder where you move all your kings and queens to (and nothing else)
  • open Terminal, type cd followed by a space, drag the folder you've just created into the Terminal window (release the mouse button once a green cross appears) and press Enter
  • type p=SOME.CRAZY.STUFF followed by Enter
  • type (or even better copy/paste)

    for i in *; do f="${i%.*}"; if [[ "$p" != "$f" ]]; then zip "$f" "$f".*; fi; p="$f"; done

    again followed by Enter

  • (assuming no error message etc was displayed) quit Terminal again
  • thanks patrix. this one looks interesting. would you like to expand how to use it.
    – sukema
    Commented Dec 16, 2015 at 13:17
  • I assume you are not familiar with Terminal/bash then? I'll update the answer later (=> when I'm in front of a Mac again).
    – nohillside
    Commented Dec 16, 2015 at 13:25

you can put both into one folder and zip that folder..

otherwise you need to use tar, which is a bit more complicated...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .