Bash Shell Command to Zip a Directory, but Exclude Some Files and Folders

Bash shell script command to zip a directory while excluding some files and folders. This example zips everything in the FOLDER_TO_ZIP, but excludes the “tests” folder, the “.git” folder, the “” file, and excludes all files ending with “.sh” or “.xml”, and all temporary files with ~ in the name.

This assumes you already set up variables for FOLDER_TO_ZIP, NEW_ZIP_NAME and NEWVERSION.

# zip the $FOLDER_TO_ZIP
zip -r ${NEW_ZIP_NAME}.${NEWVERSION}.zip $FOLDER_TO_ZIP -x '*tests*' '*.git*' '*' '*.xml' '*.sh' '*~*'

See more:


Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this: