Archives

How to compress/decompress in Linux

Linux has some tools to compress files and extract archives. You can see some of them listed in the tables below. First table has the decompression commands:

Decompress Command Information
gzip -d file.php.gz
gunzip file.php.gz
Extract archives created with the gzip utility.
bzip2 -d file.php.bz2
bunzip2 file.php.bz2
Extract archives created with the bzip2 utility.
unzip archive.zip Extract archives created with the zip utility.
tar -zxvf archivefile.tgz
tar -jxvf archivefile.tbz2
Extract archives created with tar + gzip/bzip2.
-z for gzip decompression ; -j for bzip2 decompression

To see system information for each commands, type commandname –help at the terminal, like:

root@web [~]# gzip --help
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).

Mandatory arguments to long options are mandatory for short options too.

  -c, --stdout      write on standard output, keep original files unchanged
  -d, --decompress  decompress
  -f, --force       force overwrite of output file and compress links
  -h, --help        give this help
  -l, --list        list compressed file contents
  -L, --license     display software license
  -n, --no-name     do not save or restore the original name and time stamp
  -N, --name        save or restore the original name and time stamp
  -q, --quiet       suppress all warnings
  -r, --recursive   operate recursively on directories
  -S, --suffix=SUF  use suffix SUF on compressed files
  -t, --test        test compressed file integrity
  -v, --verbose     verbose mode
  -V, --version     display version number
  -1, --fast        compress faster
  -9, --best        compress better
    --rsyncable   Make rsync-friendly archive

With no FILE, or when FILE is -, read standard input.

Report bugs to <bug-gzip@gnu.org>.
root@web [~]#

So, for extracting a .gz archive, use the gzip tool:

root@web [/]# gzip -d archive_file.gz

or gunzip

root@web [/]# gunzip archive_file.gz

But how you compress your files? In the table below see some commands for compressing files/directories:

Compress Commands Information
gzip file1.htm Compress the file using gzip. 
bzip2 file1.htm Compress the file using bzip2.
zip file1.zip file1.htm Compress the file1.htm into the archive file1.zip.
tar -zcvf files1.tgz file.htm
tar -zcvf files1.tgz *.htm
tar -zcvf files1.tgz /directory/dir1/
tar -jcvf files1.tbz2 file.htm
tar -jcvf files1.tbz2 *.htm
tar -jcvf files1.tbz2 /directory/dir1/
With tar utility you can compress many files.
-z for gzip compression ; -j for bzip2 compression

For example, to compress a full directory(with all subdirectories), use:

root@web [/]# tar -czvf archive.tar.gz /home/temp2/

Another common archive type is RAR. You can download the RAR program from http://rarlabs.com/download.htm (for Linux 32/64 only a command line version is available).
How to install it:

root@web [/temp2]# wget http://rarlabs.com/rar/rarlinux-x64-5.5.b3.tar.gz
--2017-05-26 14:54:47--  http://rarlabs.com/rar/rarlinux-x64-5.5.b3.tar.gz
Resolving rarlabs.com (rarlabs.com)... 5.135.104.98
Connecting to rarlabs.com (rarlabs.com)|5.135.104.98|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 534195 (522K) [application/x-gzip]
Saving to: 'rarlinux-x64-5.5.b3.tar.gz'

100%[========================================================================================================

2017-05-26 14:54:48 (845 KB/s) - 'rarlinux-x64-5.5.b3.tar.gz' saved [534195/534195]
root@web [/temp2]# tar -zxvf rarlinux-x64-5.5.b3.tar.gz
rar/
rar/order.htm
rar/acknow.txt
rar/readme.txt
rar/default.sfx
rar/license.txt
rar/rarfiles.lst
rar/whatsnew.txt
rar/makefile
rar/rar
rar/unrar
rar/rar.txt
root@web [/temp2]# cd rar
root@web [/temp2/rar]# install rar unrar
root@web [/temp2/rar]# rar -?

RAR 5.50 beta 3   Copyright (c) 1993-2017 Alexander Roshal   23 May 2017
Trial version             Type 'rar -?' for help

Usage:     rar <command></command> - -  
               <@listfiles...> <path_to_extract\>

  a             Add files to archive
  c             Add archive comment
  ch            Change archive parameters
  cw            Write archive comment to file
  d             Delete files from archive
  e             Extract files without archived paths
  f             Freshen files in archive
  i[par]=  Find string in archives
  k             Lock archive
  l[t[a],b]     List archive contents [technical[all], bare]
  m[f]          Move to archive [files only]
  p             Print file to stdout
  r             Repair archive
  rc            Reconstruct missing volumes
  rn            Rename archived files
  rr[N]         Add data recovery record
  rv[N]         Create recovery volumes
  s[name|-]     Convert archive to or from SFX
  t             Test archive files
  u             Update files in archive
  v[t[a],b]     Verbosely list archive contents [technical[all],bare]
  x             Extract files with full path
....

Use cPanel File Manager to compress/decompress files

In this knowledge base article we will show how to compress/decompress files with the cPanel File Manager.

Steps to compress files via cPanel File Manager

  1. Login to your cPanel account
  2. Go to File Manager from the FILES Section
  3. Navigate to the directory where you have the files you want to archive.
  4. Select the files: hold the CTRL key down and click the files. If you want to archive all the files you can click the Select All button from the File Manager top menu.
  5. Click the Compress button from the File Manager top menu.
  6. On the Compress Window choose the Compress Type (Zip/Tar/GZiped Tar or Bzip2ed Tar) you want to be used. Also here choose the desired archive name. 
  7. Click the Compress File(s) button. The archive will be created and a message will let you know this.
cPanel files compress
cPanel Files Compress/Extract

Steps to decompress(extract) files via cPanel File Manager

  1. Login to your cPanel account
  2. Go to File Manager from the FILES Section
  3. Navigate to the directory where you have the archive that you want to decompress.
  4. Select the archive by clicking on it.
  5. Click the Extract button from the File Manager top menu.
  6. On the Extract Window you can choose the path where the files will be extracted. By default, the path is the current directory.
  7. Click the Extract File(s) button. Archive will be decompressed.

The video tutorial on how to compress and decompress (from 01:42):

You can also compress files and decompress archives on your computer. Use the File Manager or the FileZilla FTP client to download/upload files to your web hosting account.