88

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

136
zip -r foo.zip dir_path
| improve this answer | |
  • The -r means recursive and tells it to go through all of the sub folders. You don't really need the .zip on the filename (foo.zip) as it will create this anyway. – user2924019 Jul 21 '16 at 7:50
  • @user2924019's comment that you dont need to specify the zip name is not true in CentOS7. – killjoy Jan 21 '18 at 16:14
  • CentOS7 is exactly where I tested this. – user2924019 Jan 23 '18 at 15:51
  • 3
    Well, we've come to what is known as a Mexican standoff, now haven't we? – seizethecarp Mar 2 '18 at 21:51
  • I'm on CentOS-7 (7.5 to be exact). I ran zip -r foo my_folder and ended up with a foo.zip. Hopefully this standoff can finally come to an end. – harperville Jun 24 at 2:08
17

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.

| improve this answer | |
5

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.

| improve this answer | |
3

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy