Compression command: Compress gzip bzip2 XZ etc
Decompression command: uncompress gunzip bunzip2 UNXZ, etc.
Package (Archive) command: Tar cpio
Where compress, gzip, bzip2, and XZ can only be used for a single compressed file and cannot be used to compress directories
Compress:. Z the oldest compression command
Compress/path/to/filename-----> FILENAME. Z
Uncompress FILENAME. Z
gzip:. GZ
Gzip/path/to/somefile: The original file is deleted when the compression is complete
-d:decompress
-#:1-9, specify the compression ratio, default is 6;
Gunzip equivalent to gzip-d
Zcat unzip the information to stdout the compressed file has not changed.
That is, the content of the text file is viewed in the case of unresolved pressure.
[Email protected] tar]# LS-LH
Total 1.2M
-RW-------. 1 root root 1.2M 10:44 messages
[Email protected] tar]# gzip messages
[Email protected] tar]# LS-LH
Total 152K
-RW-------. 1 root root 152K 10:44 messages.gz
[Email protected] tar]# gunzip messages.gz
[Email protected] tar]# LS-LH
Total 1.2M
-RW-------. 1 root root 1.2M 10:44 messages
[Email protected] tar]# gzip messages
[Email protected] tar]# gzip-d messages.gz
[Email protected] tar]# LS-LH
Total 1.2M
-RW-------. 1 root root 1.2M 10:44 messages
[Email protected] tar]# gzip messages
[Email protected] tar]# zcat messages.gz | wc-l
14026
bzip2:. bz2
Compression tool with a greater compression ratio than gzip, using format approximation
bzip2/path/to/somefile
-d
-#: 1-9, default is 6
-k: Keep the original file while compressing
 BUNZIP2/PATH/TO/SOMEFILE.BZ2
bzcat decompresses files to stdout
[Email protected] tar]# LS-LH
Total 56K-------is more powerful than gzip compression capability.
-RW-------. 1 root root 55K 10:44 messages.bz2
[Email protected] tar]# bzip2- k messages
[Email protected] tar]# LS-LH
Total 1.2M
-RW-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 55K 10:44 messages.bz2
XZ:. XZ
Xz/path/to/somefile
-D
-#: 1-9, default is 6
-K: Keep the original file when compressing
unxz is equivalent to XZ--decompress.
xzcat/xzdec equivalent to XZ--decompress--stdout.
[Email protected] tar]# XZ messages
[Email protected] tar]# LS-LH
Total 36K------------------Stronger compression capability
-RW-------. 1 root root 34K 10:44 messages.xz
[Email protected] tar]# xz-dk messages.xz
[Email protected] tar]# LS-LH
Total 1.2M
-RW-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 34K 10:44 messages.xz
[Email protected] tar]# unxz messages.xz- k
[Email protected] tar]# LS-LH
Total 1.2M
-RW-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 34K 10:44 messages.xz
Zip-package and Compress (archive) files
Zip: Both archived and compressed tools are supported by default for this feature in many OS
Zip is a compression and file packaging utility for Unix, VMS,
MSDOS, OS/2, Windows 9x/nt/xp, Minix, Atari, Macintosh, Amiga, and
Acorn RISC OS. It is analogous to a combination of the Unix com-
Mands tar (1) and compress (1) and is compatible with PKZIP (Phil
Katz ' s ZIP for MSDOS systems).
Zip Filename.zip FILE1 FILE2 ...: Do not delete the original file after compression
Unzip Filename.zip
[Email protected] tar]# LS-LH
Total 1.2M
-RW-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 34K 10:44 messages.xz
[Email protected] tar]# zip messages.zip messages*
Adding:messages (deflated 87%)
ADDING:MESSAGES.XZ (deflated 0%)
[Email protected] tar]# LS-LH
Total 1.4M
-RW-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 34K 10:44 messages.xz
-rw-r--r--. 1 root root186K11:33 Messages.zip
[Email protected] tar]# Unzip Messages.zip
Archive:messages.zip
Replace messages? [Y]es, [N]o, [A]ll, [N]one, [R]ename:y
Inflating:messages
Replace Messages.xz? [Y]es, [N]o, [A]ll, [N]one, [R]ename:y
Inflating:messages.xz
[Email protected] tar]# LS-LH
Total 1.4M
-RW-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 34K 10:44 messages.xz
-rw-r--r--. 1 root root 186K 11:33 messages.zip
Archive: Archiving, archiving by itself does not imply compression
Tar:. Tar Archive tool
GNU ' tar ' saves many files together into a single tape or disk archive,
and can restore individual files from the archive.
-C: Create an archive file
-F File.tar: Archive file (destination file) Use archive file or device archive
-X: Expand Archive Extract files from an archive
--xattrs: Preserves extended attribute information for files when archiving
-T: Do not expand the archive to see directly what files are archived--list list the contents of an archive
-V,--verbose
verbosely List Files processed
-Z,--gzip
Filter the archive through gzip
-ZCF: Archive and invoke gzip compression
-ZXF: Call gzip to unzip and expand Archive,-Z option to omit
-j,--BZIP2
Filter the archive through bzip2
-jcf:bzip2
-JXF: Call bzip2 to unzip and expand Archive,-Z option to omit
-j,--XZ
Filter the archive through XZ
-jcf:xz rhel6
-JXF:
TAR-CF Archive.tar Foo Bar
# Create Archive.tar from Files foo and bar.
TAR-TVF Archive.tar
# List All files in Archive.tar verbosely.
TAR-XF Archive.tar
# Extract all files from Archive.tar.
[[email protected] tar]# ls-lh
Total 1.4M
-rw-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 34K 10:44 messages.xz
-rw-r--r--. 1 root root 186K 11:33 messages.zip
[Email protected] tar]# tar-cf Messeages.tar messages*
[Email protected] tar]# LS-LH
Total 2.7M
-RW-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 34K 10:44 messages.xz
-rw-r--r--. 1 root root 186K 11:33 messages.zip
-rw-r--r--. 1 root root 1.4M 11:57 Messeages.tar
[Email protected] tar]# TAR-XVF Messeages.tar
Messages
Messages.xz
Messages.zip
[Email protected] tar]# LS-LH
Total 2.7M
-RW-------. 1 root root 1.2M 10:44 messages
-RW-------. 1 root root 34K 10:44 messages.xz
-rw-r--r--. 1 root root 186K 11:33 messages.zip
-rw-r--r--. 1 root root 1.4M 11:57 Messeages.tar
[Email protected] tar]# rm-f Messages.tar
[Email protected] tar]# TAR-ZCVF messages.tar.gz mess*
Messages
Messages.xz
Messages.zip
[Email protected] tar]# LS-LH
Total 1.7M
-RW-------. 1 root root 1.2M 10:44 messages
-rw-r--r--. 1 root root 362K 12:26 messages.tar.gz
-RW-------. 1 root root 34K 10:44 messages.xz
-rw-r--r--. 1 root root 186K 12:17 messages.zip
Messages
Messages.xz
Messages.zip
[Email protected] tar]# LS-LH
Total 1.7M
-RW-------. 1 root root 1.2M 10:44 messages
-rw-r--r--. 1 root root 362K 12:26 messages.tar.gz
-RW-------. 1 root root 34K 10:44 messages.xz
-rw-r--r--. 1 root root 186K 12:17 messages.zip
...
cpio -copy files to and from archives
[Email protected] tar]# cp/boot/initramfs-2.6.32-573.el6.x86_64.img.
[Email protected] tar]# file/boot/initramfs-2.6.32-573.el6.x86_64.img
/BOOT/INITRAMFS-2.6.32-573.EL6.X86_64.IMG: gzip Compressed Data, from Unix, last modified:wed Jan 6 08:43:04 20 Max Compression
[Email protected] tar]# mv initramfs-2.6.32-573.el6.x86_64.img initramfs-2.6.32-573.el6.x86_64.img.gz
[Email protected] tar]# gzip-d initramfs-2.6.32-573.el6.x86_64.img.gz
[[Email protected] tar]# file initramfs-2.6.32-573.el6.x86_64.img
Initramfs-2.6.32-573.el6.x86_64.img: ASCII cpio archive (SVR4 with no CRC)
File compression, decompression, and packaging commands