Compression
Compact format: GZ, bz2, XZ, zip, Z, and so on.
Compression algorithm: The algorithm is different, the compression ratio is also different.
Comperss:filename.z low Compression ratio.
Uncompress
Gzip
Filename.gz
Only files can be compressed.
#gzip [OPTION] FILENAME compression is complete and the source file is deleted.
[OPTION]
-D unzip the file, equivalent to Gunzip.
-num compression ratio. 1-9, default is 6.
#gunzip filename.gz The source file is deleted when the decompression is complete.
#zcat FILENAME to view the contents of a text file without being pressed.
bzip2;
A compression tool that has a greater compression ratio than gzip. The source file is also deleted when the decompression is complete. Only files can be compressed.
filename.bz2
#bzip2 [OPTION] FILENAME
-D unzip the file, equivalent to BUNZIP2.
-K--keep Keep the source file when compressing.
-num compression ratio. 1-9, default is 6.
#bunzip2 filename.bz2
#bzcat filename.bz2 to view the contents of a text file without being pressed.
Xz
Filename.xz
#xz [OPTION] FILENAME
The source file is deleted when the compression is complete. Only files can be compressed.
[OPTION]
-D unzip the file.
-num compression ratio. 1-9, default is 6.
-K--keep Keep the source file when compressing.
#unxz filename.xz The source file is deleted when the decompression is complete.
#xzcat FILENAME to view the contents of a text file without being pressed.
#xzdec usage is similar to XZ.
Zip:
The compression ratio is small, but the files within the directory and directory can be compressed. is both compressed and archived, and the source files are not deleted after compression.
#zip [OPTION] filename.zip FILE1 FILE2 ...
#unzip Filename.zip
Archive (archive):
The archive itself does not imply this compression.
Filename.tar
Tar
#tar [OPTION]
-C Create an archive file.
The-F Filename.tar Operation's archive file is named filename.
-X expands the archive.
--xattrs preserves extended attribute information for files when archiving.
-T does not expand the archive to view the contents of the archive file.
-V displays the procedure.
-Z Call gzip
-j Call bzip2
-j Call XZ
For example:
#tar-JCF abc.tar.xz Test*.txt
#tar-JCF abc.tar.bz2
#tar-ZCF abc.tar.gz
#tar-ZXF abc.tar.gz
#tar-JXF ABC.TAR.BZP2
#tar-JXF Abc.tar.xz
#tar-xf Abc.tar.xz tar automatically determines the compression software, so the-J|J|Z option can be ignored.
Cpio
Copy files into archives.
Practice:
1. Write a script that lets the user enter several files from the keyboard, and the script can compress several files into a single file.
#!/bin/bash
Read-p "Three files:" FILE1 FILE2 FILE3
Read-p "dir" dir
Read-p "COM Type:[gzip|bzip2|xz]:" $TYPE
Case $TYPE in
Gzip
TAR-ZCF [$DIR].tar.gz $FILE 1 $FILE 2 $FILE 3
BZIP2)
TAR-JCF [$DIR].tar.bz2 $FILE 1 $FILE 2 $FILE 3
Xz
TAR-JCF [$DIR].tar.xz $FILE 1 $FILE 2 $FILE 3
*)
echo "unkown!"
Exit 9
Esac
This article is from "Small Private blog" blog, please be sure to keep this source http://ggvylf.blog.51cto.com/784661/1606461
Linux compression and archiving