How to use zip command in ubuntu, Linux, Unix
below command include all hidden files.
# zip 1.zip * .[^.]*
$ sudo zip 1.zip * .[^.]*
zip all files and folders including subfolder and hidden files
# zip -r 1.zip your_folder/.
To ignore a folder when using the zip command, utilize the -x option for exclusion.
Here is the general syntax:
Code
zip -r archive_name.zip source_directory -x "source_directory/folder_to_ignore/*"
Explanation:
zip -r: This initiates thezipcommand with recursive inclusion, meaning it will include all subdirectories and files within thesource_directory.archive_name.zip: This is the name you want to give your resulting zip file.source_directory: This is the main directory you are zipping.-x: This is the exclude option."source_directory/folder_to_ignore/*": This specifies the folder to be excluded.source_directory/folder_to_ignore/: This provides the full path to the folder you wish to exclude, relative to thesource_directory.*: This wildcard ensures that all contents withinfolder_to_ignoreare also excluded.- Quotes (
"): Using quotes around the exclusion pattern is important, especially if the path contains spaces or special characters, to prevent the shell from interpreting them.
Example:
To zip a directory named my_project and exclude a subfolder named node_modules:
Code
zip -r my_project_archive.zip my_project -x "my_project/node_modules/*"
Excluding multiple folders:
You can specify multiple folders to exclude by adding more -x options:
Code
zip -r my_project_archive.zip my_project -x "my_project/node_modules/*" -x "my_project/logs/*"
Excluding folders by name (regardless of path):
To exclude any folder with a specific name, regardless of its location within the source directory, you can use a wildcard at the beginning:
Code
zip -r my_project_archive.zip my_project -x "*/node_modules/*"
This would exclude any node_modules folder found within my_project or any of its subdirectories.






