Zip and unzip files and folders in Ubuntu
This is how I zip and unzip my files and folders in Ubuntu from my terminal. I'm writing this here so I can refer back to it when I get old and forget all about it.
Zip a file or folder
Install the zip if it's not already installed-
sudo apt install zip
Now you can zip a folder with this command-
zip -r zipfile.zip source_folder
-r - Use this if the source folder has more than one file or folders so it can recursively zip them all together. You can skip this if you are only zipping one file.
zipfile.zip - This is the name of the zip file which is created by the command.
source_folder - This is the folder name/path you want to zip
This command will make the .zip file in the same folder where source_folder is present. If you want a different location for your zip file then replace the zipfile.zip with a full path of your choice.
Unzip a .zip file
Install unzip if it is not installed already on your ubuntu server-
sudo apt install unzip
Navigate to the directory where your zip file is saved and type this command in your terminal-
Zip/Unzip with more powers
If you need more power with the zip and unzip in Ubuntu terminal then continue reading this-
Excluding Files from a Zip Archive
Exclude files from zip by using the -x flag like below example where we are excluding the .DS_Store files
zip archive.zip images/ -x ".DS_Store"
If you want to exclude all .DS_Store files then you can do this-
zip -r archivename.zip archive_directory -x "*.DS_Store"
If the directory includes subdirectories which may contain the file that you want to exclude then use below command to exclude the DS_store files from subdirectories as well-
zip -r archive.zip directory -x "*/.DS_Store"