create zip unzip file linux

How to Create Zip and Unzip File in Linux

In this article we will look at how to create zip files & directories in Linux, and unzip files in Linux to extract zip files. Zip files allow you to archive multiple files & directories into a single file and save space. You can use these steps to zip files & folders in Ubuntu, Debian, CentOS, Redhat, Fedora and other Linux systems.

 

How to Create Zip and Unzip File in Linux

Here are the steps to create zip and unzip file in Linux. Before proceeding further, please ensure you have installed Zip and Unzip software in your system. Here are the steps to install zip and unzip in Linux.

 

How to Create Zip file in Linux

The zip command allows you to compress and archive one or more files, and directories into a single .zip file. Here’s the syntax of zip command in linux to compress one or more files

$ zip [options] zipfile files_list

In the above command you need to specify the zip filename into which your files need to be compressed

For example, here’s the command to zip one file sample.txt

$ zip sample.zip sample.txt

 

Bonus Read : How to Install Zip File in Linux

 

How to Zip Multiple Files in Linux

Here’s the command to zip multiple files (sample1.txt, sample2.txt, sample3.txt) into a single zip file.

$ zip samples.zip sample1.txt sample2.txt sample3.txt

 

How to Zip Folders and Subfolders in Linux (Zip Recursive)

Here’s the syntax to zip all files in a directory recursively.

$ zip -r zipfile /path/to/directory

The -r flag above will recursively zip all files in your directory. Here’s an example to create zip archive of all files & subfolders in /product directory

$ zip -r product.zip /home/product

 

Bonus Read : How to Find Directory in Linux

 

How to Extract Zip file in Linux

The unzip command allows you to extract zip files to present or specific directory. Here’s the syntax of unzip command in linux

$ unzip zipfile [options]

Here’s an example to extract zip file (e.g sample.zip) in linux

$ unzip sample.zip

The above command will extract content of sample.zip to your present working directory

 

How to Extract files & folders to specific folder

If you want to unzip file to specific folder then you need to use -d option and specify the path to that directory

For example, if your present working directory is /home/product and you want to extract a zip file to another specific folder (e.g /home/app) then here’s the linux command for it.

$ unzip sample.zip -d /home/app

 

Hopefully, now you can easily zip and extract files and directories in Linux.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!