Linux file compression and packaging (top)

Source: Internet
Author: User
Tags bz2

6.1 Compression Packaging Introduction

6.2gzip Compression Tool

6.3BZIP2 Compression Tool

6.4XZ Compression Tool

The size of the file after compression can not be more compressed tool to conclude that his size is based on the contents of the file and the compression tool together.

6.1 Compression Packaging Introduction

we usually download files on the Internet is generally compressed, compression will make our file space to narrow. Compressed files The time we transmit online will also be reduced, and bandwidth resources will be reduced. When it comes to bandwidth, the bandwidth used by our family is not the same as that used by the company, the download speed and upload speed of the home are not the same, and the company is equivalent. So the company's broadband is more expensive. If the files on our server are often downloaded we will compress the files (so that we can save a lot of bandwidth resources).

Before we said that the Windows system file suffix name can be categorized, but in our Linux system file suffix name is not so important, but we have to distinguish the Linux system inside the same file, use the same suffix name.

6.2gzip Compression Tool

[email protected] ~]# cd/tmp/
[[email protected] tmp]# ls
1.1.txt
1.2.txt
1.txt
Fstab
Newdisk
passwd.sh
Systemd-private-4a8637beb8de42fb8464053cf2d212d8-chronyd.service-qri1f0
Systemd-private-4a8637beb8de42fb8464053cf2d212d8-vgauthd.service-kxhywb
Systemd-private-4a8637beb8de42fb8464053cf2d212d8-vmtoolsd.service-xak1rp
Systemd-private-9efcc82ee01b48909302a65e60af7a1d-chronyd.service-1iixso
Systemd-private-9efcc82ee01b48909302a65e60af7a1d-vgauthd.service-7iwwfh
systemd-private-9efcc82ee01b48909302a65e60af7a1d-vmtoolsd.service-jqno61
Systemd-private-a655ede1d77c4fa6ae782f90c506592b-chronyd.service-dqvyew
Systemd-private-a655ede1d77c4fa6ae782f90c506592b-vgauthd.service-e2oych
Systemd-private-a655ede1d77c4fa6ae782f90c506592b-vmtoolsd.service-yxllvs
Txt
Xxx.conf
[email protected] tmp]# mkdir d6z
[email protected] tmp]# CD!$
CD d6z
[[email protected] d6z]# find/etc/-type f-name "*conf"-exec Cat {} >> 1.txt \;"Take a look at how this find is used."
[email protected] d6z]# du-sh 1.txt"View the size of a file or directory"
240K 1.txt
[[email protected] d6z]# find/etc/-type f-name "*conf"-exec Cat {} >> 1.txt \;
[Email protected] d6z]# Du-sh 1.txt
704K 1.txt
[[email protected] d6z]# CP 1.txt 2.txt
[[email protected] d6z]# cat 2.txt >> 1.txt
[Email protected] d6z]# Du-sh 1.txt
1.2M 1.txt
[[email protected] d6z]# cat 2.txt >> 1.txt
[Email protected] d6z]# Du-sh 1.txt
2.2M 1.txt
[[email protected] d6z]# cat 2.txt >> 1.txt
[Email protected] d6z]# Du-sh 1.txt
2.2M 1.txt
[[email protected] d6z]# cat 2.txt >> 1.txt
[Email protected] d6z]# Du-sh 1.txt
4.2M1.txt

[email protected] d6z]# wc-l 1.txt"See how many lines a file has"
60770 1.txt
[[email protected] d6z]# gzip 1.txt"Compress 1.txt Files"
[email protected] d6z]# du-sh 1.txt"We didn't see the file when we looked at the size of the file."
Du: Unable to access ' 1.txt ': no file or directory
[[email protected] d6z]# ls"You can see that our 1.txt file is 1.txt.gz."
1.txt.gz 2.txt
[email protected] d6z]# gzip-d 1.txt.gz"-d option will unzip our files"
[[email protected] d6z]# ls
1.txt 2.txt
[email protected] d6z]# du-sh 1.txt"Before compressing this file size is 4.2M, after compression we unzip to find that our file size becomes 2.4M, this is because our previous file He is like a sponge, memory is a gap, and we compress and then unzip will cause our file size changes." "
2.4M 1.txt

[email protected] d6z]# wc-l 1.txt "We look at the number of lines in the file again without changing"
60770 1.txt
gzip compression level

Gzip compression is available in levels, from 1 to 9 levels, respectively. The higher the compression level, the more resources the CPU consumes.

1 levels are the least rigorous (that is, the compressed files are not 9 levels small)

9 levels are the most rigorous (that is, the compressed file is much smaller than the 1 level)

[[email protected] d6z]# ls
1.txt 2.txt
[email protected] d6z]# gzip-1 1.txt"Specify compression Level 1"
[email protected] d6z]# du-sh 1.txt.gz"Compressed file 1.txt.gz size 732k"
732K1.txt.gz
[email protected] d6z]# gunzip 1.txt.gz"This is also an uncompressed command with the-D option acting the same"
[email protected] d6z]# gzip-9 1.txt"Specify compression level 9"
[email protected] d6z]# du-sh 1.txt.gz"Compressed file 1.txt.gz size 616k"
616K1.txt.gz
[email protected] d6z]# gzip-d 1.txt.gz
[[email protected] d6z]# gzip 1.txt"If we don't specify a level default is Level 6"
[email protected] d6z]# du-sh 1.txt.gz"Default compressed file 1.txt.gz size 620k"
620K1.txt.gz
[[email protected] d6z]# file 1.txt.gz"View details of our compressed files"
1.txt.gz:gzip compressed data, was ' 1.txt ', from Unix, last Modified:fri Jan 5 06:59:22 2018
[email protected] d6z]# zcat 1.txt.gz"This command can view the contents of our compressed file"
[[email protected] d6z]# ls
1.txt.gz 2.txt
[email protected] d6z]# gunzip 1.txt.gz
[email protected] d6z]# gzip-c 1.txt >/tmp/1.txt.gz"This method compresses the file, you can specify where we will place the compressed file, and our source files will not disappear." The above experiment compresses our source files and disappears only compressed files. "
[[email protected] d6z]# ls
1.txt2.txt
[email protected] d6z]# ls/tmp/1.txt.gz
/tmp/1.txt.gz
[[email protected] d6z]# file!$"file, let's see."
File/tmp/1.txt.gz
/tmp/1.txt.gz:gzip compressed data, was ' 1.txt ', from Unix, last Modified:fri Jan 5 06:59:22 2018

[email protected] d6z]# gzip-d-c/tmp/1.txt.gz >/tmp/d6z/jieya1.txt.gz "I can also specify where to put the extracted files, and the original compressed files will not disappear." The above experiment will disappear when we unzip the file. "
[email protected] d6z]# du-sh 1.txt jieya1.txt.gz
2.4M 1.txt
2.4M jieya1.txt.gz
[Email protected] d6z]# wc-l 1.txt jieya1.txt.gz
60770 1.txt
60770 jieya1.txt.gz
121540 Total Dosage

6.3BZIP2 Compression Tool

The Bzip2 tool compresses files more hard than the Gzip tool compresses files, and the more the file compresses the more resources the CPU consumes. Default Level 9

[email protected] d6z]# bzip2 1.txt "Compress command, prompt us not to install BZIP2 tool"
-BASH:BZIP2: Command not found
[email protected] d6z]# Yum install-y bzip2
[email protected] d6z]# bzip2 1.txt"Compress command"
[[email protected] d6z]# ls
1.TXT.BZ2 2.txt jieya1.txt.gz
[email protected] d6z]# du-sh 1.txt.bz2"View our compressed file size using bzip2"
244K1.txt.bz2"We can see his compression is very small, we used to use gzip compression when the size is 620k"
[email protected] d6z]# bzip2-d 1.txt.bz2 "-d option is the meaning of decompression"
[[email protected] d6z]# ls
1.txt 2.txt jieya1.txt.gz
[email protected] d6z]# du-sh 1.txt"No compressed file size"
2.4M 1.txt
[Email protected] d6z]# bzip2 1.txt
[email protected] d6z]# bunzip2 1.txt.bz2"Unzip the file command, as with the-D option"
[[email protected] d6z]# ls
1.txt 2.txt jieya1.txt.gz
[email protected] d6z]# bzip2-c 1.txt > 3.txt.bz2"Preserve source file compression, and specify the path of the compressed file"
[[email protected] d6z]# ls
1.txt2.txt3.txt.bz2Jieya1.txt.gz

[[email protected] d6z]# file 1.txt.bz2 "Use this command to view the details of our compressed files"
1.TXT.BZ2:BZIP2 compressed data, block size = 900k

Sometimes some people just put the compressed file suffix name to you change this time you cat view is useless inside are binary files. At this point, we thought of using the file command to see what file he was.

[[email protected] d6z]# ls
1.txt.bz2 2.txt 3.txt.bz2 jieya1.txt.gz
[Email protected] d6z]# MV 3.txt.bz2 3.txt
[[email protected] d6z]# ls
1.txt.bz2 2.txt 3.txt jieya1.txt.gz
[email protected] d6z]# less 3.txt
"3.txt" may be a binary file. See it Anyway?
[[Email protected] d6z]# file 3.txt
3.TXT:BZIP2 compressed data, block size = 900k
[[Email protected] d6z]# file 2.txt
2.txt:utf-8 Unicode Text

[email protected] d6z]# Bzcat 3.txt.bz2 "We can use this command to view a compressed file"

6.4XZ Compression Tool

The XZ tool compresses files that are less compressed than the BZIP2 tool, and of course the more compressed the file, the more resources the CPU consumes. Default Level 9

The following command does not do a detailed introduction you can refer to the above two compression tools to understand.

[[email protected] d6z]# ls
1.txt 2.txt 3.txt.bz2 jieya1.txt.gz
[email protected] d6z]# XZ 1.txt
[[email protected] d6z]# ls
1.txt.xz 2.txt 3.txt.bz2 jieya1.txt.gz
[email protected] d6z]# du-sh 1.txt.xz
56K1.txt.xz
[email protected] d6z]# unxz 1.txt.xz
[[email protected] d6z]# ls
1.txt 2.txt 3.txt.bz2 jieya1.txt.gz
[email protected] d6z]# du-sh 1.txt
2.4M1.txt
[email protected] d6z]# xz-z 1.txt
[[email protected] d6z]# ls
1.txt.xz 2.txt 3.txt.bz2 jieya1.txt.gz
[[email protected] d6z]# xz-d-C 1.txt.xz >/tmp/1.txt.xz
[Email protected] d6z]# xz-c/tmp/1.txt >/tmp/d6z/5.txt.xz

[[email protected] d6z]# ls
1.txt.xz 2.txt 3.txt.bz2 5.txt.xz jieya1.txt.gz

[Email protected] d6z]# Xzcat 5.TXT.XZ

Amin linux:http://v.apelearn.com

Momco-51cto Blog: http://blog.51cto.com/13518197


Linux file compression and packaging (top)

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.