How to exclude files and folders when creating zip archive using linux commands?
Explained the solutions with multiple examples.
Exclude files from zip
Refer the follwing examples for different cases.
Example 1:
To exclude all the files(e.g: .pdf, .git, .svn) in the specific folder only when zipping.
zip -r zip-name.zip zip_folder -x zip_folder/subfolder/*.pdf
Example 2:
To exclude all the files in the main folder and also from all sub folders when zipping.
zip -r zip-name.zip zip_folder -x '*.pdf'
Exclude files from zip
Refer the following examples for different cases.
Example 1:
To exclude the single or specific folder only when zipping.
zip -r zip-name.zip zip_folder -x \*zip_folder/sub_directory1/*
Try alternate command,
zip -r zip-name.zip zip_folder -x '*zip_folder/sub_directory1/*'
Example 2:
To exclude the multiple folders when zipping.
zip -r zip-name.zip zip_folder -x \*zip_folder/sub_directory1/* \*zip_folder/sub_directory2/another_subdirectory/*
Try alternate command,
zip -r zip-name.zip zip_folder -x '*zip_folder/sub_directory1/*' -x '*zip_folder/sub_directory2/another_subdirectory/*'