Linux Common compression tools: gzip, bZIP, XZ, these compression tools do not compress the directory
-------------------------------------------------
gzip, bZIP, XZ compression ratios: xz>bzip>gzip
The compression ratio usually has 1-9, 9 levels, the command does not specify the compression level, the default use Level 6, the larger the compression ratio, the more CPU resources, compressed files are also about small, can use parameters, such as:-4, specify the compression ratio level;
The suffix name of the gzip, BZIP2, XZ Compressed package:. GZ,. bz2,. XZ, for example: After compressing the file test, the compressed package is named test.gz
gzip, bzip2, XZ extract command: Gunzip = gzip-d, bunzip2 = bzip2-d, Unxz = xz–d
By default, when a file is compressed, the source file is deleted, bzip2, XZ can use the parameter-K, the compressed file does not delete the source file, and gzip can be achieved by output redirection: Gzip–c file > file.gz
If you are not in the press, use the following command to view the contents of the compressed package file
*.gz use: Zcat
*.bz2 use: Bzcat
*.xz use: Xzcat
-------------------------------------------------
Since the directory cannot be compressed directly, we need to archive the directory (archive) into a single file before compressing
Linux Common Archive Command: Tar
tar command :
Common Parameters
-C: Create an archive
-X: Expand Archive
-F FileName: Specifies the file name after the archive, typically with *.tar as the filename
-T: Do not expand the archive to view the list of archived files
-C: Specifies the path after the archive is expanded
after the directory can be archived into a file, the compression tool is called to compress
-Z: Call gzip for compression
-J: Calling bzip2 for compression
-J: Calling XZ for compression
--xattrs: Preserve Extended Properties of files after archiving
[[email protected] scripts]# cp -r /etc/init/ ./ # Copy the init directory to the current directory [[email protected] scripts]# ls123 123.xz init[[email protected] scripts]# tar -cf test.tar init #将init目录归档为test. Tar [[Email protected] scripts]# ls123 123.xz init test.tar[[email protected] scripts]# tar -tvf test.tar #查看归档明细 Drwxr-xr-x root/root 0 2015-04-12 02:02 init/-rw-r--r-- root/root 430 2015-04-12 02:02 init/rcs-emergency.conf #省略 ... [[email protected] scripts]# ls /tmp/yum.log- - - - - - - - - - - - - - - - - - -[[email protected] scripts]# tar -xf test.tar -C /tmp #指定展开归档到/tmp directory [[email protected] scripts]# ls /tmp/init yum.log- - - - - - - - - - - - - - - - - - -[[email protected] scripts]# tar -jcf test1.tar.xz init/r* #归档并压缩 [[email protected] scripts]# ls123 123.xz Init test1.tar.xz test.tar[[email protected] scripts]# tar -jxf test1.tar.xz -C /tmp #解压并展开, where j can be omitted, the TAR command automatically calls the compression tool for decompression according to the compression format [email protected] scripts]# ls /tmp/init/rc.conf rcS.conf Rcs-emergency.conf rcs-sulogin.conf
zip command : archive, compress at the same time, suffix named. zip, extract command for unzip,unzip-v can view the file details in the compressed package without the pressure
[[email protected] scripts]# ls123 123.xz init[[email protected] scripts]# zip -r test.zip init #如果要直接压缩目录, the-R is required for recursive operation, and the directory is written as Init with less-R /* or this init/r* (file starting with R in the directory) adding: init/ (stored 0%) adding: init/ rcs-emergency.conf (deflated 34%) adding: init/quit-plymouth.conf (deflated 37%) adding: init/start-ttys.conf (deflated 33%) ... #省略 ... [[email protected] scripts]# ls123 123.xz init test.zip- - - - - - - - - - - - - - - -[[email protected] scripts]# unzip -v test.zip #unzip -v Can check the compressed package file details under the condition of archive: test.zip length method Size cmpr&nbsP; date time crc-32 name-------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 04-12-2015 02:44 00000000 init/ 430 Defl:N 283 34% 04-12-2015 02:44 d32c7c59 init/rcs-emergency.conf #省略 ... -------- ------- --- ------- 7946 4676 41% 15 files[[email protected] scripts]#
This article is from the "Arvin Lau" blog, be sure to keep this source http://64314491.blog.51cto.com/2784219/1631307
Linux archiving, compression