Linux

How to create and extract zip,tar file in Linux?

How to create and extract zip,tar file in linux

In this tutorial, I will explain how to create zip, tar and tgz file. Also how to extract zip, tar and tgz file.

What is ZIP file extension?

The Zip file extension does not have a full form.

A file with the ZIP file extension is a ZIP Compressed file and is the most widely used archive format you’ll run into.

A ZIP file, like other archive file formats, is simply a collection of one or more files and/or folders but is compressed into a single file for easy transportation and compression.

Let’s understand the zip command :

  1. Create zip file :

Folder Name : app

zip -r app_backup.zip app/*

  1. Create multiple folders zip file :

Folder Name : app,design,pub etc.

zip -r app_deign_pub_backup.zip app/* design/* pub/*

  1. To extract or unzip zip file :

Zip File Name : app_backup.zip

unzip app_backup.zip

What is TGZ file extension?

A TGZ file is a TAR Archive file that has been compressed using Gnu Zip (gzip) software. Commonly used on UNIX and Linux systems, TAR archives bundle a collection of files into a single file for easier distribution or backup.

  1. Create tgz file :

Folder Name : pub

tar --exclude='./' -zcvf pub.tgz pub

  1. Create multiple folders tgz file :

Folder Name: app,vendor,pub etc.

tar --exclude='./' -zcvf app_vendor_pub.tgz app vendor pub

  1. Create tgz file for all folder on root path :

tar --exclude='./' -zcvf allfolder.tgz .

  1. Create tgz file with exclude folder :

Exclude Folder : var

tar --exclude='./var' -zcvf source_code.tgz .

  1. Create tgz file with exclude multiple folders :

Exclude Folder : var,pub etc.

tar --exclude='./var' --exclude='./pub' -zcvf source_code.tgz .

  1. Extract tgz file :

Folder Name : source_code.tgz

tar --strip-components=1 -zxf source_code.tgz

  1. Create tar.gz file :

Folder Name : design

tar -czvf design.tar.gz design

  1. Create tar.gz file with multiple folders :

Folder Name : app,design,vendor etc.

tar -czvf app_design_vendor.tar.gz app design vendor

  1. Extract tar.gz file :

Folder Name : design.tar.gz

tar -xzvf design.tar.gz

🙂 Happy Coding. Keep Liking & Sharing 💻

Tagged , ,