Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to zip all files in a given directory with the zip command? I've heard of using *.*, but I want it to work for extensionless files, too.

share|improve this question
Have you tried navigating one-level up from your desired directory and doing zip myarch.zip mydir/*? – Joseph R. Nov 28 '12 at 16:46
or better zip -r myarch.zip mydir/* – Adam Mar 16 at 17:52
up vote 160 down vote accepted

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 myfiles

where myfiles 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.

share|improve this answer
You might want to add, that it is considered a good practice to contain everything in the archive in a top-level directory - so that one doesn't pollute his/her current directory on extraction. – peterph Nov 28 '12 at 16:54
@peterph done. Though this is less a convention in zip files than in e.g., tarfiles, I'm afraid. – derobert Nov 28 '12 at 16:59
unfortunately yes. Probably due to the windows heritage of drag'n'drop to the desktop and linux heritage of working with source codes. – peterph Nov 28 '12 at 17:03
Keep in mind that * shell-globbing doesn't include dotfiles (ie. filenames beginning with .). This is another advantage to zipping the whole directory by name. – mrb Nov 28 '12 at 17:29
But using -r includes the directory itself, which breaks what I'm doing. Wouldn't * include . and ..? – tkbx Nov 28 '12 at 17:30

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.

share|improve this answer

Use zip command to zip entire directory using command:

zip -r directoryname.zip directoryname
share|improve this answer
I do not see how your answer adds anything to the answers already given 2.5 years ago. – Dubu Jun 11 '15 at 7:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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