Linux Learning Notes (19) file compression

Source: Internet
Author: User
Tags bz2

I. Common compressed files

Windows. rar. zip. 7z

Linux. Zip,.gz,.bz2,.xz,.tar.gz,.tar.bz2,.tar.xz
File compression saves memory and can save transfer speed

Ii.. gzip

First, create a folder/tmp/d6z/
Found some big files to write 1.txt
For example
find /etc/ -type f -name "*conf" -exec cat {} >> 1.txt \ ;
Perform several more times

gzip 1.txt

You can compress the file 1.txt and delete the source file
You can see that the previous 1.txt size is 8.5m
1.9m after compression

gzip -d 1.txt.gz

Unzip the file, this time found that 1.txt is smaller than the original, this is because the compression will remove some unnecessary space,

wc -l 1.txt  

Can view the number of file lines, before and after compression can see whether the file changes
Gzip-1 1.txt
Here 1 is the compression level, a total of nine levels, the default is 6, the smaller the number, the lower the compression rate, the larger the file, the smaller the resource consumption, and vice versa, the compression level of general compression will remain the default
Gunzip 1.txt.gz
can also be used to extract files

To view information about a compressed file

zcat 1.txt.gz

You can view the contents of a file in a compressed package

gzip -c 1.txt > /root/1.txt.gz

Compresses the file to the specified path and specifies the file name without deleting the source file

gunzip -c /root/1.txt.gz > /tmp/1.txt.new

Unzip the compressed file to the specified folder and specify the file name without deleting the original compressed file
Note: gzip does not compress the directory
Parameter options

-A or--ascii: use ASCII text mode;
-D or--decompress or----uncompress: unpack the compressed file;
-F or--force: Forcibly compress the file. Ignores the existence of a file name or a hard connection and whether the file is a symbolic connection;
-H or--help: online help;
-L or--list: Lists information about compressed files;
-L or--license: Displays version and copyright information;
-N or--no-name: When compressing a file, the original file name and time stamp are not saved;
-N or--name: When compressing the file, save the original file name and time stamp;
-Q or--quiet: No warning message is displayed;
-R or--recursive: recursively handles all files and subdirectories under the specified directory;
-S or < compress the tail string > or----suffix< compress the tail string;: Change the compressed word tail string;
-T or--test: Test whether the compressed file is correct;
-V or--verbose: Displays the instruction execution process;
-V or--version: Displays version information;
-< compression efficiency;: Compression efficiency is a value between 1~9, the default value is "6", specifying the larger the value, the higher the compression efficiency;
--best: The effect of this parameter is the same as specifying the "-9" parameter;
--fast: The effect of this parameter is the same as specifying the "-1" parameter.
Third, bzip2

If not installed, install BZIP2 first
yum install -y bzip2

Bzip2 1.txt

bzip2 1.txt  / bzip2 -z 1.txt bzip2 -d 1.txt.bz2 / bunzip2 1.txt.bz2 bzip -# 1.txt  //#范围1-9,默认9 不能压缩目录 bzcat 1.txt.bz2 bzip2 -c 1.txt > /root/1.txt.bz2 bzip2 -c -d /root/1.txt.bz2 > /tmp/1.txt.new2

BZIP2 usage Basic Same as Gzip

Bzcat 1.txt.bz2
View the file contents of a compressed file
Parameter options

-C or--stdout: The results of compression and decompression are sent to standard output;
-D or--decompress: Perform decompression;
-F or-FORCE:BZIP2 when compressing or decompressing, if the output file has the same name as an existing file, the preset does not overwrite the existing file. to overwrite. Please use this parameter;
-H or--help: online help;
-K or--keep:bzip2 deletes the original file after it is compressed or uncompressed. To keep the original file, use this parameter;
-S or--small: Reduce the amount of memory used during program execution;
-T or--test: Test. bz2 the integrity of the compressed file;
-V or--verbose: Displays detailed information when compressing or decompressing a file;
-Z or--compress: enforces compression;
-V or--version: Displays version information;
--repetitive-best: If there is duplication of data in the file, this parameter can be used to improve the compression effect;
--repetitive-fast: This parameter can be used to speed up performance if there are duplicate data in the file.
Iv. XZ

The usage of XZ compression is also similar to gzip, bzip2

xz 1.txt  / xz -z 1.txt            xz -d 1.txt.xz / unxz 1.txt.xz xz -# 1.txt  //#范围1-9,默认9 不能压缩目录 xzcat 1.txt.xz xz -c 1.txt > /root/1.txt.xz xz -d -c /root/1.txt.xz > 1.txt.new3

Size of files after compression
Gzip>bzip2>xz
That is, XZ is the most resource-intensive, compressed file is minimal

Linux Learning Notes (19) file compression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.