Zip all files in directory?

You can just use *; there is no need for *.*. File extensions are not special on Unix. * matches zero or more characters—including a dot. So it matches foo.png, because that's zero or more characters (seven, to be exact).

Note that * by default doesn't match files beginning with a dot (neither does *.*). This is often what you want. If not, in bash, if you shopt -s dotglob it will (but will still exclude . and ..). Other shells have different ways (or none at all) of including dotfiles.

Alternatively, zip also has a -r (recursive) option to do entire directory trees at once (and not have to worry about the dotfile problem):

zip -r myfiles.zip mydir

where mydir is the directory containing your files. Note that the produced zip will contain the directory structure as well as the files. As peterph points out in his comment, this is usually seen as a good thing: extracting the zip will neatly store all the extracted files in one subdirectory.

You can also tell zip to not store the paths with the -j/--junk-paths option.

The zip command comes with documentation telling you about all of its (many) options; type man zip to see that documentation. This isn't unique to zip; you can get documentation for most commands this way.


In my case I wanted to zip each file into its own archive, so I did the following (in zsh):

$ for file in *; do zip ${file%.*}.zip $file; done

Another way would be to use find and xargs: (this might include a "." directory in the zip, but it should still extract correctly. With my test, zip stripped the dot before compression) find . -type f -exec zip zipfile.zip {} +

(The + can be replaced with \; if your version of find does not support the + end for exec. It will be slower though...)

This will by default include all sub-directories. On GNU find -maxdepth can prevent that.