Tar, Gzip, Zip is the compressed form of packaging and basic data on Linux systems. Specifically, Tar used to encapsulate data, GZip and Zip compressed data can do both jobs.
Tar help pack the files / folders in one file, very helpful for backing up data. Typically, Tar files ending in .tar. To minimize file size, we need to add options or bunzip2 gzip compression. Synthetic options include
# tar -cvf folder1 folder2 filename.tar file1 file2
Filename.tar the tar file name you create. File1, folder1 … the files, the folder you want packed in tar file (packed in the order listed).
For example, you are working in / usr, should pack folder / usr / bin, folder / boot / grub and /boot/abc.img[19459005file]
# tar -cvf filename.tar bin / boot / grub /boot/abc.img
Files can be stored in the form filename (abc.img) or in the form attached file path (boot / abc.img). Meanwhile, in the process of extracting data, the file will be placed in the correct path saved.
Packing and data compression
Tar normally helps encapsulate data. To compress the data to reduce the amount, you should use the optional compression
z for gzip (.gz format) or
j for bunzip (.bz2 format)
# tar -czvf folder1 folder2 filename.tar.gz file1 file2 or # Tar -cjvf folder1 folder2 filename.tar.bz2 file1 file2
Archives skip files on demand
During the packaging process and store data, which can remove the file as required using option
For example, remove from the packaging .pyc file directory data /usr/lib/python2.6/site-packages
# tar -cvf /usr/lib/python2.6/site-packages filename.tar --exclude = '*. Pyc'
Displays total storage capacity has been
totals helps show the total storage capacity is
# tar -cvf folder1 file1 filename.tar --totals Total bytes ghi: 20561920 (20MiB, 354MiB / s)
Listing the contents inside archives
To view the contents inside the first tar file, use the option
v to give out the information on the display includes permissions, owner, date / time …
# tar -tvf filename.tar
Add new, updated content into an archive
r to add content into an archive
# tar -rvf add_file1 filename.tar add_file2
To update data into an archive already, use the option
u (a special need to update the backup file)
# tar -uf filename.tar
This command will compare the time modification of the contents on the outside and inside of the archives. Inside files will be updated if newer external file.
Deleting data in archives
delete to remove content at the request of archives
# tar --delete filename.tar -f file1 file2
# tar -xvf filename.tar
This command will not remove the .tar file that will only extract the data inside the tar file into the current directory. In case the file is saved with path included, if the path does not exist, the system will automatically create a corresponding folder to place the file. Depending on how you package the data to extract the file location can change
For example, you are working in / boot / grub and wants encapsulation 1.map files in that folder.
For .tar.gz gzip compressed files you need to use more options
z (with gzip compressed files) or optional
j (with zip bunzip)
# tar -xzvf filename.tar.gz # Tar -xjvf filename.tar.bz2
Bung several files / folders specific
# tar -xvf filename.tar file1 file2
Bung into one directory to another
To extract the data in the current folder elsewhere, you need to specify the path of the destination folder with the option
# tar -xvf filename.tar -C / directory
# tar -xvf test.tar -C / boot / efi the entire file will be unbent test.tar in the / boot / efi
GZIP is used quite commonly in platforms Unix / Linux. GZIP can only work on one file or one stream of data, so can not store more files. So, if you want to use for multiple files then we have to use them before the TAR package.
# gzip filename
In this case, the original file automatically converted into compressed files. For example,
# gzip test.php will convert into test.php.gz test.php
Set the compression level
The degree of compression is the custom in the range from 1 to 9. In particular, the fastest 1 ~ fast compression but lowest compression level to 9 ~ highest compression level best but slowest compression
# # gzip gzip -1 --fast filename or filename
# gzip -9 --best filename or # gzip filename
Check the compressed file attribute
# gzip -l filename.gz
# gzip -l hocvps.tar.gz uncompressed_name compressed ratio uncompressed 23724096 64901120 63.4% hocvps.tar
# gzip -d filename
Then, the compressed files automatically converted into the original file. For example,
# gzip -d test.php.gz will convert into test.php test.php.gz
First, you need to check the installation zip in the systems.
# rpm -q zip zip package is not installed or Package zip-3.0-1.el6_7.1.x86_64 already installed and Latest version
Conduct install Zip if no
# yum -y install zip Installed: zip.x86_64 0: 3.0-1.el6_7.1
# zip filename.zip filename1 filename2
In particular, the zip file filename.zip will be created from the compressed filename1 and filename2
folder into 1 Compressed zip file
-r zip compression to the entire folder and files inside.
# zip -r test.zip folder1
# unzip filename.zip
Meanwhile, in filename.zip file will be unpacked into the current folder, compressed files remain
If the file exists in the directory decompression, the program will ask you about your options replace
[y] es, [n] o, [A] ll, [N] one, [r] ename