Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zip folder recursively, save for a given sub folder (Linux)

Tags:

In Linux zip, is it possible to zip a folder recursively except for a given sub-path?

For instance, to zip 'base_folder' and all its sub folders except 'base_folder/sub_folder'.

Is it possible? And if so, how?

like image 258
john-jones Avatar asked Jun 26 '12 12:06

john-jones


People also ask

How do I zip a directory with subdirectories in Linux?

Syntax : $zip –m filename.zip file.txt 4. -r Option: To zip a directory recursively, use the -r option with the zip command and it will recursively zips the files in a directory. This option helps you to zip all the files present in the specified directory.

Can you zip folders with subfolders?

Creating a zip folder allows files to be organized and compressed to a smaller file size for distribution or saving space. Zip folder can have subfolders within this main folder. Select the operating system below for instructions on how to zip and compress folders.

How do I create a subfolder in a zip file?

To create the new folder, navigate into the folder in which you wish to create your new folder, right-click and choose New Folder from the shortcut menu. The Create a Folder dialog will appear. The dialog shows the full path of the folder in the Zip file in which the new folder will be created.

How do I zip all files in a directory in Linux?

The easiest way to zip a folder on Linux is to use the “zip” command with the “-r” option and specify the file of your archive as well as the folders to be added to your zip file. You can also specify multiple folders if you want to have multiple directories compressed in your zip file.


2 Answers

zip -r base_folder.zip base_folder -x base_folder/sub_folder/\* base_folder/another_sub_folder/\*

(I have incorporated the improved information from your experience that you have kindly offered in your comment.)

For more information: man zip

like image 158
minopret Avatar answered Nov 17 '22 12:11

minopret


You can use tar with --exclude, and use the -z option to gzip the output tar file.

like image 31
Andy Lester Avatar answered Nov 17 '22 12:11

Andy Lester