Linux compressed with files, directory compression and archiving
File compression type: gzip, bzip2, XZ
Directory compression: Zip
Archive: Tar
Various file compression commands are implemented in the following several functions, but the syntax is slightly different
Gzip:
File suffix: gz
Compression: gzip files, delete original files
[Email protected] test]# lltotal 192-RW-------. 1 root root 193746 Sep 12:05 test01[[email protected] test]# gzip test01[[email protected] test]# lltotal 32-RW-------. 1 root root 29378 Sep 12:05 test01.gz
Decompression: Gunzip compressed files, delete compressed files
[Email protected] test]# gunzip test01.gz [[email protected] test]# lltotal 192-RW-------. 1 root root 193746 Sep 12:05 test01
Preserve original file compression: Gzip-c File > Compressed file
[Email protected] test]# gzip-c test01 > Test02.gz[[email protected] test]# lltotal 224-RW-------. 1 root root 193746 Sep 12:05 test01-rw-r--r--. 1 root root 29378 Sep 13:24 test02.gz
View files Zcat compressed files directly within a compressed package
[Email protected] test]# Zcat test02.gz | Less
Bzip2
File suffix: bz2
Compress: bzip2 file, delete original file
Unzip: Bunzip2 compressed file, will delete compressed file
Preserve original file compression: Bzip2-k original file
[Email protected] test]# bzip2-k test02 [[email protected] test]# lltotal 212-rw-r--r--. 1 root root 193746 Sep 13:24 test02-rw-r--r--. 1 root root 19565 Sep 13:24 test02.bz2
To view files directly within a compressed package: Bzcat Compressed files
Xz
File suffix: xz
Compress: XZ file will delete the original file
Unzip: Unxz compressed file, will delete compressed file
Preserve original file compression: Xz-k source file
To view files directly within a compressed package: Xzcat Compressed files
The compression ratios of these commands are
Xz>bzip2>gzip
Directory Compression zip
Special usage: 1. Need to make self-made compressed file, 2 compressed after the original file will not be deleted 3 can be individually compressed files
Format: Zip compressed file. zip Original file
[Email protected] test]# zip test02.zip test02 adding:test02 (deflated 85%) [[email protected] test]# lltotal 244-rw-r-- R--. 1 root root 193746 Sep 13:24 test02-rw-r--r--. 1 root root 19565 Sep 13:24 test02.bz2-rw-r--r--. 1 root root 29515 Sep 13:32 test02.zip
To compress a directory, you need to specify all files
[[email protected] tmp]# zip test.zip test/* adding:test/test02 (deflated 85%) adding:test/test02.bz2 (deflated 3) a Dding:test/test02.zip (stored 0%)
Unzip: Unzip compressed document. zip, can only extract to the current directory
[Email protected] test02]# unzip Test.zipArchive:test.zip inflating:test/test02 inflating:test/test02. bz2 Extracting:test/test02.zip [[email protected] test02]# ll test/total 244-rw-r--r--. 1 root root 193746 Sep 13:24 test02-rw-r--r--. 1 root root 19565 Sep 13:24 test02.bz2-rw-r--r--. 1 root root 29515 Sep 13:32 test02.zip
Archive
Create an archive
Format: Tar CF archive file. Tar all folders or files to be archived
Do not like zip, specify all files in directory
[Email protected] test02]# TAR-CF Testtar.tar test/dir/
Expand archive to current directory, do not delete compressed files
Tar xf tar file
[Email protected] test02]# TAR-XF Testtar.tar
View files within an archive
TAR-TF tar file
[Email protected] test02]# TAR-TF testtar.tartest/test/test02.ziptest/test02test/test02.bz2dir/
Archive post-Compression call
Compress and Archive
Format: TAR-ZCF file. tar.gz file
-Z can replace other compression format, suffix should also have corresponding modification
-z:gzip,-J:BZIP2,-J:XZ
[Email protected] test02]# TAR-ZCF test.tar.gz test/[[email protected] test02]# ll test.tar.gz-rw-r--r--. 1 root root 78836 Sep 13:54 test.tar.gz
Unzip files that have been archived and compressed, without concern for the format compression
T-format AR XF compressed and archived files
[Email protected] test02]# TAR-XF test.tar.gz
Linux Compression Archive Summary