Skip to main content

compression



Linux: Compression How-to: tar gzip bzip2 xz 7zip rar zip


This page shows you how to decompress or compress file or directory in Linux.

tar archive (.tar)

“tar” is unix standard for archiving a folder. Tar makes a directory into a single file. Tar does not compress.
  • To archive a folder, do: 
#tar cvf new name.tardirname
#tar cvf archive.tar file1 file2 file3
  • To unarchive, do: tar xvf filename

  • To list contents#tar tf archive.tar(to list contents of file)
Red color- archive file
Blue- directory
Black-file
Here's what the option means:
  • x → eXtract
  • v → verbose, meaning print out status.
  • f → file.
  • c → create.
“tar” can untar and decompress in one step:
  • To tar and compress with gzip: tar xvfzfilename
  • To tar and compress with bz2: tar xvfjfilename
  • To tar and compress with xz: tar xvfJfilename

gzip compression (.gz)

gzip is unix standard for compressing a single file. gzip is often used together with tar.
  • To compress: gzipfilename
  • Decompress: gzip -d filename or gunzipfilename

bzip2 compression (.bz2)

Alternative to gzip, for compressing a single file. File size smaller than gzip.
  • To compress: bzip2 filename
  • Decompress: bzip2 -d filename

xz compression (.xz)

Alternative to gzip, for compressing a single file. File size smaller than bzip2. xz is derived from 7-zip.
  • To compress: xzfilename
  • Decompress: unxzfilename or xz -d filename

 

 

#du  -h /etc [34 mb]



#tar cJf /root/etcbackup.tar.xz /etc [5.7 mb]

 

#tar cjf /root/etcbackup.tar.bzip2 /etc [7 mb]

 

#tar czf /root/etcbackup.tar.gz /etc [8.4 mb]

 

 

zip archive (.zip)

ZIP (file format) is for archiving and compressing a folder or single file. Originally from Microsoft Windows world.
  • To create archive: zip -r new name.zipdirname
  • To extract: unzip filename

7-zip archive (.7z)

7-zip is for archiving and compressing a folder (similar to zip). Originally from Microsoft Windows world. Compresses the best.
The 7z util can decompress many formats.
  • To create archive: 7z a -t7z new name.7zdirname
  • To extract: 7z e filename

rar archive (.rar .rev .r00 .r01 .r02 …)

RAR (file format) is proprietary, from Windows world. Often used for pirated videos. File extension: {.rar .rev .r00 .r01 .r02 …}.
  • To extract rar files, use 7z e filename.

Compression File Size Comparison

  • emacs-24.2.tar.gz 49M
  • emacs-24.2.tar.bz2 40M
  • emacs-24.2.tar.xz 33M



Comments

Popular posts from this blog

sed

Sed Command in Linux/Unix with examples SED command in UNIX is stands for stream editor and it can perform lot’s of function on file like, searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening it, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it. o     SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution). o     SED command in unix supports regular expression which allows it perform complex pattern matching. Syntax: sed OPTIONS... [SCRIPT] [INPUTFILE...] Example: Consider the below text file as an input. $cat > geekfile.txt unix is great os. unix is opensource. unix is free os. learn operating system. unixlinux which one you choose. unix is easy to learn.unix ...

initramfs" file is deleted or corrupted on your RHEL or CentOS 7

Initrd/Initramfs image provides the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root filesystem and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root filesystem which was mounted from initrd/initramfs is then moved to a directory and can be subsequently unmounted. Their are chances that either you might have accidentally deleted "initramfs" file from the /boot partition or it is corrupted due to some reason.  Then boot process will get interrupted and you will see below error: error: file '/initramfs-3.10.0-957.el7.x86_64.img' not found. Good news is you can still recover this "initramfs" by following below steps: Step 1 :  Mount RHEL or CentOS 7 ISO image on your physical server and boot from it. In case you are using HPE Prolient server you can mount this ISO image on iLO, if this is virtual environment then mount it accordingly and reboot...

nw commands

troubleshoot commands in Linux.   1. ifconfig ifconfig (interface configurator) command   is use to initialize an interface, assign IP  Address to interface and enable or disable  interface on demand. With this command  you can view IP Address and Hardware / MAC   address assign to interface and also MTU (Maximum transmission unit) size. # ifconfig   eth0       Link encap:EthernetHWaddr 00:0C:29:28:FD:4C inet addr:192.168.50.2   Bcast:192.168.50.255   Mask:255.255.255.0           inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link           UP BROADCAST RUNNING MULTICAST   MTU:1500   Metric:1           RX packets:6093 errors:0 dropped:0 overruns:0 frame:0  ...
# # #