126

How do I make a .zip file that contains every file AND every folder in the directory?

  • 1
    I use 'tar': tar -zcvf archive.tar.gz directory/ http://unix.stackexchange.com/questions/93139/can-i-zip-an-entire-folder-using-gzip – njuhgn Oct 20 '14 at 05:21

4 Answers4

185
zip -r foo.zip dir_path
Wesley Rice
  • 2,200
26

Try:

zip -r filename.zip /path/to/folder

Note - this will go recursively, i.e. it will zip all folders and all subfolders of the given folder.

icyrock.com
  • 5,292
  • where obviously /path/to/folder can be a regex, like /path/to/folder/myprefix*, which will put in the archive only the files and folders starting by myprefix. – Tms91 Jun 29 '23 at 15:48
6

Use the -r option. From zip(1):

-r

Travel the directory structure recursively; for example:

zip -r foo foo

The name of the zip file comes first. "Recursively" means that the zip file will include subfolders of the given folder, the subfolders of those folders, and so on.

PleaseStand
  • 4,919
4

If you are bound to a zip, I'd use:

zip -r zipfilename directoryPath

The -r is the key, but you can find all the options here.