Compression and packaging of Linux files and file systems

Source: Internet
Author: User
Tags unpack

Compression and packaging of Linux files and file systems

Came in to learn Linux, but the Linux command too much, afraid to remember the way to use the blog record to write their own learning process, and later forget can also read their own blog to check:

    • Common compression commands for Linux systems
    • Compress
    • Gzip,gcat
    • Bzip2,bzcat
    • Package Command: Tar
Common compression commands for Linux systems

In the Linux environment, most of the compressed files are *.tar, *.tar,*.gz, *.tgz, *.gz, *. Z, *.bz2, below we list common ZIP file extensions:
*. Z ————— >compress Program zip file
*.gz ————— >gzip Program Compressed files
*.BZ2 ———— –>BZIP2 Program Compressed files
*.tar ————— the >tar program to package data and does not compress
*.tar.gz files packaged ———— the >tar program, and are compressed with gzip.
*.tar.bz2 ——— –>tar The files packaged by the program and is compressed by bzip2.

Linux系统常见的压缩命令就是gzip与bzip2,至于compress已经不再流行了。gzip是由GNU计划所开发出来的压缩命令,该命令已经替换了compress。后来GNU有开发出bzip2这个压缩比更好的压缩命令。不过这些命令通常只能针对一个文件来压缩与解压缩,如此一来,每次压缩都要一大堆文件,岂不是很烦人?此时打包软件tar就很重要了。
Compress

Compress is already very old, but learning to practice practiced hand is still possible. Now the Linux distribution seems to have not been installed by default, so practiced hand can install ncompress this software.

I am prompted here that I have installed, so basically nothing to do with, if the first installation may require you to enter Y, and then continue to install.
Next look at how to use the Compress command.

[[email protected] ~]#compress [-rcv] 文件或目录   <==这里指压缩[[email protected] ~]#uncompress 文件名.Z          <==这里指解压缩选项与参数:-r : 可以连同目录下的文件也同时给予压缩。-c : 将压缩数据输出成为standard output(输出到屏幕)-v : 可以显示压缩后的文件信息以及压缩过程中的文件信息

Compress compressed Files

Compress unzip a file

After decompression, you will find that the Man_db.conf.z file does not, if you want to save the file can use the-C syntax.

Gzip,zcat

Gzip is the most widely used compression command. Currently gzip can decompress files compressed by compression software such as compress, zip and gzip. Next look at the syntax:

[[email protected] ~]#gzip [-cdtv#] 文件名[[email protected] ~]#zcat 文件名.gz参数:-c : 将压缩的数据输出到屏幕上,可通过数据流重定向来处理;-d : 解压缩需要用到的参数;-t : 可用来校验一个压缩文件的一致性,看看文件是否有错误;-v : 显示原文件/压缩文件的压缩比等信息;-# : 压缩等级,-1最快,但其压缩比较差,-9最慢,但压缩比最好,默认-6.

gzip Compressed Files

ZCAT Read Compressed file contents

gzip Unzip files

Bzip2,bzcat

Gzip is created to replace compress, while bzip2 is to replace Gzip and provide a better compression ratio, below the specific usage:

[[email protected] ~]#bzip2[-cdkzv#] 文件名[[email protected] ~]#bzcat 文件名.bz2参数:-c : 将压缩的数据输出到屏幕上;-d : 解压缩需要用到的参数;-k : 保留原文件,而不会删除原始的文件;-z : 压缩的参数;-v : 显示原文件/压缩文件的压缩比等信息;-# : 压缩等级,-1最快,但其压缩比较差,-9最慢,但压缩比最好.

Package Command: Tar

Although Gzip and bzip2 can also be compressed for the directory, the compression of these two directories refers to the operation of compressing all files in the directory "separately".
This command function, which packages multiple files or directories into a large file, can be called a "package command". Linux below is the famous tar. Tar can package multiple directories or files into a single large file, and it can also compress the file simultaneously with GZIP/BZIP2 support.
The parameters of tar are very many, we only talk about a few common parameters, more parameters can be self-man tar query.

[[Email protected] ~] #tar [-j|-z] [CV] [-f new filename] filename ... <== pack and compress [[email protected] ~] #tar [-J|-Z][TV] [-F New file name ] <== View file name [[email protected] ~] #tar [-j|-z] [XV] [-F new file name] [-C directory] <== extract parameters:-C : Create a new package file with-V to view the file name (filename) that is packaged in the process.-T : See what file names are in the contents of the packaged files, and focus on viewing filenames.-x : Unpack or unzip the feature, can be solved with-C(uppercase) in the special directory. It is particularly noted that-c,-t,-x cannot be present in a string of command lines at the same time .-J : compression/Decompression through BZIP2 support, at which point the filename is preferably *.tar.bz2.-z : compression/decompression via gzip support, at which point the file name is preferably *.tar.gz.-v : during the compression/decompression process, the file name being processed is displayed.-f filename : The name of the file to be processed after-F. It is recommended that-F write a separate parameter. - C directory : This parameter can be used to decompress in a particular directory when decompressed.-P : retains the original permissions and attributes of the backed up data, typically used for backing up (-C) Important configuration files.- P : retains the decision path, that is, allows the backup data to contain the root directory exists meaning.--exclude=file : do not package file in the process of compression.

In fact, the simplest way to use tar is simply to memorize the following:
-Compression: Tar-jcv-f filename.tar.bz2 The name of the file or directory to be compressed.
-Enquiry: Tar-jtv-f filename.tar.bz2
-Unzip: Tar-jxv-f filename.tar.bz2-c to extract the directory

Then filename.tar.bz2 is our custom file name, Tar does not actively generate the file name created. We want to customize. So the extension is important. If you do not add [-j|-z], the file name is best taken as . Tar. If the-j parameter represents bzip2 support, the file name is best taken as . tar.bz2 because BZIP2 will produce the. bz2 extension. As for the IF-Z parameter, which represents the support for gzip, the file name is best taken as *.tar.gz.

    • Use tar to add-j or-Z parameters back up/etc/directory

See two ways to compress, bzip2 compression is indeed higher than gzip compression, so it is recommended to use the bzip2 to backup.

    • Query the data contents of the Tar file (view the file name), and whether the backup file name has the meaning of the root directory
    • To view the file name is very simple, you can do this:

    • Unzip the extracted file to the specified location (the application of the-C parameter)

    • How to unlock a single file only
      First we need to use-JTV to find the file name you want, and then untie the file name.
      1. First find the file name we want, assuming that the shadow file is unpacked.

      2. Unpack the file. The syntax and practice are as follows:


    • The practice of packaging a directory, but not including some files in that directory (–exclude=file)
      Let's say we want to pack/etc/root these important directories, but we don't want to package the files that start with/root/etc* because we're all the backup files we just created. And assuming this new packaging file is to be placed called/root/system.tar.bz2, of course, this file does not package itself (because this file is placed under/root), at this time we can help through the –exclude. So, can do:
[root@www ~]#tar -jcv -f /root/system.tar.bz2 --exclude=/root/etc* \>--exclude=/root/system.tar.bz2 /etc /root

For details, see < Linux Private cuisine > Nineth Chapter->linux File and file system compression and packaging

Compression and packaging of Linux files and file systems

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.