Linux File compression and Archiving
Linux File compression and Archiving
File compression
Common compression Commands include gzip and bzip2.
Gzip Command Format
Gzip [-acdfhlLnNrtvV19] [-S suffix] [name...]
Command Parameters
-C -- stdout -- to-stdout
Write the output content to the standard output port and keep the original file unchanged.
-D -- decompress -- uncompress
Extract
-F -- force
Force Compression
-H -- help
Print help information
-L -- list
List compressed file compression statistics
-L -- license
Print version and copyright information
-Q -- quiet
Do not display warning information
-R -- recursive
Recursive Compression
-S. suf -- suffix. suf
The suffix of the compressed file is. suf, and the default suffix is. gz.
-T -- test
Integrity check of compressed files
-V -- verbose
Detailed information is displayed during compression.
-V -- version
Print version and copyright information
-# -- Fast -- best
Set the compression level. # The value range is 1 ~ 9, # The larger the value, the slower the compression speed, the better the compression effect. The default value is 6.
Instance
A) compressed file
bkjia@bkjia:~/bkjia/linux/cmdline$ gzip foo
B) decompress the file
bkjia@bkjia:~/bkjia/linux/cmdline$ gzip -d foo.gz
bkjia@bkjia:~/bkjia/linux/cmdline$ gunzip foo.gz
C) List compressed file compression statistics
bkjia@bkjia:~/bkjia/linux/cmdline$ gzip -l foo.gz compressed uncompressed ratio uncompressed_name 4150 26134 84.2% foo
D) specify the compression level
bkjia@bkjia:~/bkjia/linux/cmdline$ gzip -v9 foofoo: 84.9% -- replaced with foo.gz
E) only view the content of the compressed file.
bkjia@bkjia:~/bkjia/linux/cmdline$ date > foobkjia@bkjia:~/bkjia/linux/cmdline$ gzip foobkjia@bkjia:~/bkjia/linux/cmdline$ gzip -dc foo.gz Thu May 7 17:10:35 CST 2015
Related commands
Gunzip-extract, equivalent to gzip-d
Zless-view the compressed file content. zless test.gz is equivalent to gunzip-c test.gz | less
Zcat-similar to zless, zcat test.gz is equivalent to gunzip-c test.gz | cat
Bzip2 command
Bzip2 is similar to the gzip command, but uses different compression algorithms. This algorithm provides high-quality data compression capabilities, but reduces the compression speed. In most cases, its usage is similar to gzip, but the file compressed with bzip2 is suffixed with. bz2.
Command Format
Bzip2 [-cdfkqstvzVL123456789] [filenames...]
Command Parameters
-C -- stdout
Compress or decompress the data to the standard output.
-D -- decompress
Force Extract
-Z -- compress
-D option supplement, force File compression
-T -- test
Integrity check of compressed files
-F -- force
Forcibly overwrite the output file.
-K -- keep
Retain the original file during (unzipping) Compression
-S -- small
Reduce memory usage during compression, decompression, and check.
-Q -- quiet
Do not display warning information
-V -- verbose
Detailed information is displayed during compression.
-L -- license-V -- version
Print version and copyright information
-1 (or -- fast) to-9 (or -- best)
Set the compression level. The larger the value, the slower the compression speed, and the better the compression effect.
Instance
A) compressed file
bkjia@bkjia:~/bkjia/linux/cmdline$ bzip2 foo
B) decompress the file
bkjia@bkjia:~/bkjia/linux/cmdline$ bunzip2 foo.bz2
Related commands
Bunzip2-extract, equivalent to bzip2-d
Bzcat-extract the extracted content to the standard output. bzcat test.bz2 is equivalent to bunzip2-c test.bz2 | cat
Bzip2recover-used to repair corrupted bz2 file data
File archiving
Archive is a common file management task used in combination with compression operations. Archiving is a process of gathering numerous files and combining them into a large file.
Tar command format
Tar [OPTION...] [FILE]...
Command Parameters
-A, -- catenate, -- concatenate
Append the tar file to the archive file
-C, -- create
Create a new archive file
-D, -- diff, -- compare
Find the differences between an archive file and a file system
-- Delete
Delete a specified file from an archive file
-R, -- append
Append an object to an archive object
-T, -- list
List the content of an archive object
-U, -- update
Append only files updated compared to archive files
-X, -- extract, -- get
Extract files from archive files
Instance
A) archive foo1, foo2, and foo3 to foo.tar.
bkjia@bkjia:~/bkjia/linux/cmdline$ tar cvf foo.tar foo1 foo2 foo3
B) view the content of the archive file
bkjia@bkjia:~/bkjia/linux/cmdline$ tar tvf foo.tar-rw-rw-r-- bkjia/huey 26840 2015-05-07 19:28 foo1-rw-rw-r-- bkjia/huey 13047 2015-05-07 19:28 foo2-rw-rw-r-- bkjia/huey 348 2015-05-07 19:28 foo3
C) Extract files from archive files
bkjia@bkjia:~/bkjia/linux/cmdline$ tar xvf foo.tar
D) append foo4 to the archive file foo.tar.
bkjia@bkjia:~/bkjia/linux/cmdline$ tar rf foo.tar foo4
E) Delete foo2 from the archive file foo.tar.
bkjia@bkjia:~/bkjia/linux/cmdline$ tar -f foo.tar --delete foo2
F) archive and compress (gzip) files
bkjia@bkjia:~/bkjia/linux/cmdline$ tar zcvf foo.tar.gz foo
G) decompress the .tar.gz file.
bkjia@bkjia:~/bkjia/linux/cmdline$ tar zxvf foo.tar.gz
H) archive and compress (bzip2) files
bkjia@bkjia:~/bkjia/linux/cmdline$ tar jcvf foo.tar.bz2 foo
I) decompress the .tar.bz2 File
bkjia@bkjia:~/bkjia/linux/cmdline$ tar jxvf foo.tar.bz2
Zip command
The zip program is both a File compression tool and a file archiving tool. In Linux, gzip is the main compression command, followed by bzip2. In Linux, zip programs are used to exchange files with Windows systems, rather than compressing or archiving files.
Command Format
Zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz! @ $] [-- Longoption...] [-B path] [-n suffixes] [-t date] [-tt date] [zipfile [file...] [-xi list]
Unzip [-Z] [-cflptTuvz [abjnoqsCDKLMUVWX $/: ^] file).zip] [file (s)...] [-x xfile (s)...] [-d exdir]
Instance
A) archive foo1, foo2, and foo3 to foo.zip.
bkjia@bkjia:~/bkjia/linux/cmdline$ zip foo.zip foo1 foo2 foo3
B) archive compression directory
bkjia@bkjia:~/bkjia/linux/cmdline$ zip -r commons-beanutils-1.9.2.zip commons-beanutils-1.9.2
C) decompress the. zip file.
bkjia@bkjia:~/bkjia/linux/cmdline$ unzip commons-beanutils-1.9.2.zip
Linux-File compression and Archiving
This article permanently updates the link address: