Use of PACKAGED commands under Linux

Source: Internet
Author: User
Tags uncompress

UNIX System business use (especially data management and backup), after some research, collation, make full use of the UNIX system itself, the command tar, cpio and compress to do packaging and compression, so that it acts as a DOS-like compression software, but also in the UNIX system has universality.

In Unix systems, many files are packaged into a single vault by Cpio or tar, and then compressed with compress to achieve the goal. The methods and procedures used are described in Cpio and tar, respectively.

First, Cpio

1. File or directory packaging.

There are a number of scenarios for packaging:

A) package with sub-directories:

Find/usr/lib-print|cpio-o〉/u0/temp1.cpio

Package the files in the/usr/lib directory with subdirectories into a single vault as/u0/temp1.cpio.

If all files and subdirectories under the entire directory are packaged through the-O option, use the Find directory name-print to find out the names of all the files and subdirectories, through the pipeline "|" Passed to Cpio packaging.

B) Packaging without subdirectories:

Ls/usr/lib|cpio-o〉/u0/temp1.cpio

Package files in the/usr/lib directory (files without subdirectories) into a single vault for/u0/temp1.cpio.

C) package specific files:

You can use the Text Search command grep with the pipeline to exclude or select specific types of files to pass to Cpio packaging. such as: Ls/usr/lib/*.c|cpio-o〉/u0/temp1.cpio

or Ls/usr/lib|grep′.c$′|cpio-o〉/u0/temp1.cpio

The meaning is to find out the files in the/usr/lib directory that end in. c are packaged.

Another example: Ls/usr/lib|grep Abcd|cpio-o〉/u0/temp1.cpio, which means to find the file name in the/usr/lib directory containing ABCD characters to be packaged.

Ls/usr/lib|grep-v Abcd|cpio-o〉/u0/temp1.cpio, which means to locate files in the/usr/lib directory that do not contain ABCD characters in the file to be packaged. The-v option in the grep command means that the column containing the string is excluded.

This allows for the full use of Unix pipelines and the power of some commands to package files.

2. Compression:

Once the file is packaged, you can compress the package file with the Compress command in UNIX (/usr/bin). For general text files, the compression rate is higher, up to 81%.

Compress/u0/temp1.cpio compresses the vault/u0/temp1.cpio to/u0/temp1.cpio.z (automatically adds. Z and Deletes/u0/temp1.cpio).

3. Unzip:

The uncompress/u0/temp1.cpio.z is automatically reverted to/u0/temp1.cpio.

4. Unpacking expansion:

The unpacking of the original directory structure will be expanded to the current directory. If a relative path is packaged, when the unpacking is expanded, it is also the file data that is stored in the relative path, and if it is packaged as an absolute path, the expanded file data is also stored as an absolute path when the unpacking is expanded. Therefore note that if the relative path, you should first enter the corresponding directory and then expand.

Cd/u1

Cpio-id〈/u0/tmp1.cpio then extracts the/u0/temp1.cpio to/U1 (this assumes that Temp1.cpio is compressed with a relative path).

If you add the U option, such as Cpio-iud〈/u0/temp1.cpio, the file will be overwritten if it exists, that is, forced overwrite.

Cpio-id〈/u0/temp1.cpio *.C expands the *.c file, similar to the pkunzip-d temp1.zip unpacking function in the PKZIP software in a DOS system.

5. Display:

Cpio-it〈/u0/temp1.cpio [*.C] Displays the file name in the vault, similar to the PKUNZIP-VBNM temp1.zip function in the PKZIP software in a DOS system.

Ii. Tar

1. File or directory Packaging:

Tar-cvf/u0/temp2.tar/usr/lib

Package the files in the/usr/lib directory with subdirectories into a single vault as/u0/temp2.tar.

Tar-cvf/u0/temp2.tar/usr/lib *.c *.F

Package files (excluding subdirectories), such as *.c *.f, in the/usr/lib directory.

Note: If you specify a file such as *.c *.f or *. *, no subdirectories are included in the package. If specified as. or *, the subdirectory is included.

2. Compression:

Ibid.: Compress/u0/temp2.tar Compression for/u0/temp2.tar.z

3. Unzip:

The uncompress/u0/temp2.tar.z is reverted to/u0/temp2.tar.

4. Unpacking expansion:

Tar-xvf/u0/temp2.tar

When unpacking with a relative path, the expanded file data is stored in a relative path, and the expanded file data is stored in an absolute path if the package is packaged as an absolute path.

If you specify an expanded file name, be aware of the directory path of the file.

5. Display:

Tar-tvf/u0/temp2.tar Displays the file name in the vault. When specifying a file name, you should also note the path to the files.

These two commands have their advantages and disadvantages in relative terms.

1) tar is slower than cpio and cannot span two storage media, but the file format is common in almost all UNIX systems and is easy to use.

2) Cpio because of the pipeline function, so that its packaging when the file selection, removal function is very strong, and can span multiple media, and can back up special system files.

In addition, the compression command compress lower than the DOS PKZIP compression rate. After testing, in a directory of 527 text files Total 15.7MB, after the UNIX packaging with compress compression, size 2.1MB, the same file copied to the DOS system with PKZIP compression, the size is 1.4MB.

Use of PACKAGED commands under Linux

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.