How to Compress file/folder in Linux

Introduction

A backup, or the process of backing up, refers to the copying and archiving of computer data so it may be used to restore the original after a data loss event. The verb form is to back up in two words, whereas the noun is backup. Backups have two distinct purposes.

  • The primary purpose is to recover data after its loss, be it by data deletion or corruption.
  • Data loss can be a common experience of computer users.

Following are the methods through which we can compress the file and folders.

1) ZIP a file/folder

#zip file.zip file1 file2
#zip file.zip dir1
#zip -option file.zip dir1

How to zip a file with excluding file/folder

zip -r conference_01-01-2015_14-30.zip /var/www/conference/* -x home_backup/

2) TAR a file/folder

tar -cvf /backup/etc.tar /etc/*
tar -cvf /backup/etc.tar

3) GZIP a file/folder

gzip is the preferred compression tool for Linux. To compress the tar file using gzip, following is the command:

gzip etc.tar

To decompress the tar file using gzip, following is the command:

gzip -d etc.tar.gz

4) BZIP2 a file/folder

There is also another tool that is rapidly gaining acceptance in the Linux world: bzip2. This is supposed to become the official way of doing it in the near future, so it may be a good idea to get to know ‘bzip2’
To compress the tar file using bzip2, following is the command:

bzip2 etc.tar

To decompress the tar file using bzip2, following is the command:

bzip2 -d etc.tar.bz2
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

18 − four =