File compression Archives - CloudMinister

File compression in Linux

Here you will learn about the file compression and the full overview of types of file compression

File compression used to contain two or more file & directory in smaller size rather than original. Compression means reduce size of file.

In linux have many types of file compression
1. gzip

2. bzip2
3. xz
4. zip

 

# du -sh filename/or/path (This command use to check the size of file)

# yes “string” > file_name (This command use to copy string into file)

Alert :- immediately press (ctrl + c) after use yes command.If you not press (ctrl +c) immediately file size increase every second.

example :- 

  1. gzip :-

gzip is used to compress file but gzip not reduce more  size as compared to others. gzip extension is .gz.   

# gzip file_name (This command used for compress the file in .gz extension)


Uncompress gzip command

# gunzip  file_name.gz (This command used to unzip .gz file)

Example:- 


Create compress and tar file simultaneously 

#tar cvzf destination\path/file_name.tar.gz /source/path/ (This command used to compress in gz format and convert in tar file)

Example:- 


Uncompress and untar  file simultaneously

# tar xvzf file_name.tar.gz (This command used for uncompressing and untar file those extensions have .tar.gz or .tgz)

Example:- 

  1. bzip2

bzip2 is used to compress file bzip2 to reduce the size as compared to gzip. Bzip2 takes time to compress. Bzip2 extension is .bz2

# bzip2 file_name (This command used to compress the file with extension .bz2)

Uncompress bzip2 command

# bunzip2  file_name.bz2 (This command used to unzip .bz2      file)

Example:- 


Create compress and tar file simultaneously using bzip2 

#tar -cvjf destination\path/file_name.tar.bz2 /source/path/ (This command used to compress in bzip2 format and convert in tar file)

Example:- 

Uncompress and untar  file simultaneously using bzip2

# tar -xvf file_name.tar.gz (This command use for uncompress and untar file those extensions have .tar.bz2 or .tbz or .tb2)

Example:- 

  1. Xz

xz is used to compress file xz reduce more size as compared to other compression method.xz  extension is .xz.

# xz file_name (This command used to compress file with extension .xz)

Example:- 

Uncompress xz command

# unxz  file_name.bz2 (This command used to unzip .xz  file)

Example:- 


  1. Zip

Zip is used to compress the file or folder so that reduce the size of that package.
zip is available in linux,windows and unix. Many other software available that work same as zip. example:- WinRAR, 7zip etc.

 

Note: before use zip command first install zip package.

In centos installation :- # yum install zip -y

In ubuntu installation :- # apt-get install zip -y

Zip current all directory and file

# zip file_name.zip * (This command use to zip all current working directory and file) 

Recursively zip all directory file

# zip -r file_name.zip directory\path (This command use to recursively zip all file in a directory)

Exclude some file in zip 

# zip -r file_name.zip directory\path –exclude “*.extension”

(This command use to zip all file in directory but exclude some files using exclude option)

Extract zip file 

# unzip file_name.zip (This command use to extract zip file)

Extract zip file into directory 

# unzip file_name.zip -d directory\path (This command use to extract zip file into a directory)

Get started with CloudMinister Today