Packaging and compression commands for basic Linux knowledge

Source: Internet
Author: User
Tags gz file

Common compressed file extensions in Linux:

* Files compressed by the. Z compress Program (used at the earliest stage) are compressed to replace the source file;
*. Zip is a file package program on the exaggerated platform. It is applicable to Linux, windows, and Mac OS systems;
*. Bz2 Bzip2 files compressed by the program;
*. Files compressed by the GZ gzip program;
* The files packaged by the. Tar program are not compressed;
* .Tar.gz tar files are compressed by the gzip program;
* .Tar.bz2 tar package and compress it with bzip2.

In reality, the compress compression command is no longer the default compression software. Common compression commands are gzip and Bzip2. But these are just compression commands, only for a single file. The tar program can "package" a large number of files into one file, or even do the same for directories. However, tar does not support compression. Later, tar and gzip were combined for ease of use.

Tar command details

Tar [-cxtzjvfppn] file and directory

Parameters:

-C: Create parameter for creating a compressed file ).

-X: parameters of the extracted file.

-T: view the files in the tarfile.

Note that only one of the three-C,-X, and-T types can exist simultaneously.

-Z: does it have the gzip attribute at the same time? Whether gzip compression is required.

-J: Does it have Bzip2 attributes at the same time? Whether to use Bzip2 for compression.

-V: displays files during compression.

-F: name of the file to be compressed and saved. Note: When this parameter is added, it must be placed behind other parameters.

Tar-ZCFV practice.tar.gz practice (error)

Tar-zcvFPractice.tar.gz practice (correct)

-P: uses the original attributes of the original file and does not change according to the user.

-P: absolute paths can be used for compression.

-N: a new date (yyyy/mm/DD) will be packed in.

-- Exclude file: Do not package file during compression.

Common instances

1. Package all files in the practicedirectory of the current directory into practice.tar.gz (gzip compression)

Tar-CVF practice.tar.gz practice (pack only without compression)

Tar-zcvf practice.tar.gz practice (packaged and compressed with gzip)

2. Package all files in the practicedirectory of the current directory into practice.tar.bz2 (Bzip2 compression)

Tar-jcvf practice.tar.bz2 practice (packaged and compressed with Bzip2)

3. Check which files are compressed in the current compressed file.

Tar-ztvf practice.tar.gz

4. compress the specified file to practice.tar.gz.

Tar-zcvf practice.tar.gz file1 file2 file3 dir1 dir2 dir3

5. decompress the tar.gz file to the specified directory (/home/anatherdir /).

Tar-zxvf practice.tar.gz-C/home/anatherdir/

6. Decompress a file (file1) in the tar.gz compressed file or/and a directory (DIR ).

Tar-zxvf practice.tar.gz file1 DIR/

7. compress the files in the practice directory later.

Tar-N '2014/1/14'-zcvf practice.tar.gz practice

The result is as follows.

Practice/
Practice/cfile.tar.gz
Tar: practice/pipes: file not changed; no output
Practice/a. c
Practice/pipes. c
Practice/Hello. c
Practice/oushu
Practice/dir1/
Tar: practice/A: file not changed; no output
Tar: practice/Hello: file not changed; no output
Practice/oushu. c

8-inch compressed practicesub-directory, but not a specific file of file1.txt

Tar -- exclude practice/file1.txt-zcvf practice.tar.gz practice

Related Article

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.