Zipping folders and their contents into a .zip file in Linux

82

18

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

sdfhdfgujsdfbgdfsb

Posted 2010-11-23T03:37:20.390

Reputation:

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 – 2014-10-20T05:21:10.817

Does it need to be a .zip or are you just after a compressed file? – None – 2010-11-23T03:41:13.470

Answers

126

zip -r foo.zip dir_path

Wesley Rice

Posted 2010-11-23T03:37:20.390

Reputation: 1 580

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 – 2016-07-21T07:50:31.723

@user2924019's comment that you dont need to specify the zip name is not true in CentOS7. – killjoy – 2018-01-21T16:14:07.473

CentOS7 is exactly where I tested this. – user2924019 – 2018-01-23T15:51:08.577

3Well, we've come to what is known as a Mexican standoff, now haven't we? – seizethecarp – 2018-03-02T21:51:13.340

16

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

Posted 2010-11-23T03:37:20.390

Reputation: 4 623

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.

PleaseStand

Posted 2010-11-23T03:37:20.390

Reputation: 4 051

Where the .zip file goes after zipping? – Siraj Alam – 2017-07-27T17:56:54.937

To the path specified. foo in this example. – Mathias Lykkegaard Lorenzen – 2020-01-03T11:56:05.330

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.

Tim Joseph

Posted 2010-11-23T03:37:20.390

Reputation: