How do I make a .zip file that contains every file AND every folder in the directory?
4 Answers
zip -r foo.zip dir_path
-
1The -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. Jul 21, 2016 at 7:50 -
@user2924019's comment that you dont need to specify the zip name is not true in CentOS7.– killjoyJan 21, 2018 at 16:14
-
-
5Well, we've come to what is known as a Mexican standoff, now haven't we? Mar 2, 2018 at 21:51
-
1I'm on CentOS-7 (7.5 to be exact). I ran
zip -r foo my_folder
and ended up with afoo.zip
. Hopefully this standoff can finally come to an end. Jun 24, 2020 at 2:08
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.
-
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 bymyprefix
.– Tms91Jun 29 at 15:48
Use the -r
option. From zip(1):
-rTravel 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.
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.