First, brief
Compression is a mechanism for reducing the file size of a computer by a specific algorithm, which reduces the file size, enables faster transmission of files over the network, and reduces the disk footprint of files. Reverse is the decompression
Two, tools
1,compress/umcompress
Suffix name. Z, very old compression tool, is obsolete.
2,gip, bzip2, XZ
(1) Gzip/gunzip: Compression/Decompression will delete the original file
Syntax: gzip [option] Compress (unzip) file name
Suffix name:. gz
# Common options: #-#: Compression ratio, default = 6, range 1 to 9 #-D: Unzip (gunzip) #-C: Output the compressed junction to standard output
Zcat somefile.gz: No pressure to view the contents of gzip compressed files
For example:
# compression Specify target path storage [[email protected] tmp]# gzip -c /etc/passwd > /tmp/passwd.gz [[email protected] tmp]# ls -hl total 24k -rw-r--r--. 1 root root 672 Apr 20 11:05 passwd.gz -rwxr-xr-x. 1 root root 20K Apr 20 10:47 rc.sysinit # Unzip [[email protected] tmp]# gzip -d /tmp/passwd.gz [[email protected] tmp]# ls -hl total 24K -rw-r--r--. 1 root root 1.6k apr 20 11:05 passwd -rwxr-xr-x.&nBsp;1 root root 20k apr 20 10:47 rc.sysinit
(2) BZIP2/BUNZIP2: Compression/Decompression will delete the original file
Syntax: bzip2 [option] Compress (extract) file name
Suffix name:. bz2
# Common options: #-#: Compression Ratio, default 6 range is 1-9 #-D: Extract (BUNZIP2) #-C: Output the compressed junction to standard output #-K: Keep the original file
Bzcat somefile.bz2: No pressure to view the contents of the bz2 compressed file
(3) XZ/UNXZ compression/decompression will delete the original file
Syntax: XZ [options] Compress (unzip) file name
Suffix name:. xz
# Common options: #-#: Compression Ratio, default 6 range is 1-9 #-D: Extract (UNXZ) #-C: Output the compressed junction to standard output #-K: Keep the original file
Xzcat somefile.xz to view the contents of the XZ compressed file
gzip, BZIP2,XZ does not support the compression of the directory, and compression and decompression will delete the original file.
3,zip/unzip: Archive compression
Zip is the compression program, unzip is the decompression program
Syntax: Zip zipfile.zip src_file ...
[[email protected] ~]# zip a.zip/etc/passwd# zip all.zip *.jpg # This command compresses a directory by compressing all. jpg files into a zip package
[[Email protected]~]# zip-r grub.zip/boot/grub # Compress a directory [email protected]]# unzip grub.zip-d/opt/# Unzip
4,tar Archive and Compress
can be implemented to package multiple files into a single file, which is an archive file
Syntax: tar [options]-f tarfile.tar src_file ...
(1) Create an archive:
Tar
-c:create, creating
-V: Show more information
-f:filename.tar
# Package Two directories or target + files into one package [email protected] desktop]# TAR-CVF ss.tar/boot//etc/passwd
(2) Expand Archive:
Tar
-x:extract, extract
-V: Show more information
-f:filename.tar
[Email protected] desktop]# TAR-XVF Ss.tar
(3) View archive:
Tar
-T: View the files inside the Tarfile
-f:filename.tar
[Email protected] desktop]# TAR-TVF Ss.tar #更为详细信息
(4) Tar can be compressed or decompressed directly via the option Call compression tool
-z:gzip
-j:bzip2
-j:xz
Archive and Compress groups:-ZCF,-JCF,-JCF
Suffix name:. Tar. [GZ|BZ2|XZ]
Decompression:-ZXF,-JXF,-JXF combination, can also be abbreviated tar XF tarfile.tar[.gz|. bz2|. XZ] No matter how it is compressed, it will be extracted with the corresponding tool
If multiple options are connected to write, then the F option must be followed by tarfile.tar[.gz|. bz2|. Xz
-can be added without any extra.
-c/path/to/somedir can specify the extracted directory
For example:
# compress the/boot directory into the/tmp directory [[email protected] tmp]# pwd/tmp# gzip [[email protected] tmp]# tar zcf boot.tar.gz /boot/[[email protected] tmp]# File boot.tar.gz boot.tar.gz: gzip compressed data, from unix, last  MODIFIED: MON APR 20 12:48:37 2015# BZIP2[[EMAIL PROTECTED] TMP] # tar jcf boot.tar.bz2 /boot[[email protected] tmp]# file boot.tar.bz2 boot.tar.bz2: bzip2 compressed data, block size = 900k# xz[[ Email protected] tmp]# tar jcf boot.tar.xz /boot[[email protected] tmp ]# file boot.tar.xz boot.tar.xz: xz compressed data# put/tmp/ boot.tar.gz compressed files to the /tmp/test/ directory [[email protected] tmp]# tar xf /tmp/ boot.tar.gz -c /tmp/test/[[email Protected] tmp]# ls /tmp/test/boot
The END.
This article is from the "Learning God It-linux lecturer-mk" blog, please be sure to keep this source http://xuegod.blog.51cto.com/9708186/1636328
Linux compression and decompression tools