Slashism

Slashism

Zip and unzip files and folders in Ubuntu

Zip and unzip files and folders in Ubuntu

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

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:

unzip zipfile.zip

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 the below command to exclude the DS_store files from subdirectories as well:

zip -r archive.zip directory -x "*/.DS_Store"
 
Share this

Impressum

🙋‍♂️ Hello there,

My name is Pankaj, and I am the author of Slashism. I hope that you learn something useful today.

If you like my content and want to stay updated then subscribe to my newsletter in the header.

You can also follow me on Twitter and say hello.

If you would like to request a particular article/topic covered or would want to discuss something, then please start a discussion here on Github Discussions

⭐ Keep learning, keep growing ⭐

Proudly part of