File compression and decompression in Linux

Source: Internet
Author: User
Tags gz file uncompress

For many users, it is easier to compress or decompress files by using tools such as ARJ and WinZip in DOS and Windows environments. However, in Linux, how does one compress and decompress files? Based on Red Hat 6.0, this article introduces several methods and techniques for compressing and extracting files, hoping to help readers.

Command: Compress

Format: compress option file list

Function: uses the Lempel-Ziv compression method to compress files or compress standard input.

Option:-r recursive operation. If a directory variable is specified, all files in the directory and Its subdirectories are compressed.

-C returns the compressed data to the standard output. By default, the compressed data is returned to the file.

-V shows the compression percentage of each folder.

Explanation: When compress is used to compress a file, the extension. Z will be added after the original file name. If no file is specified, the standard input is compressed and the standard output is returned.

Example: Objective: To compress the/mnt/lgx/a1.doc File

Command: # compress/mnt/lgx/a1.doc

Result: The a1.doc. Z file is generated after compression.

Command: uncompress

Format: uncompress option file list

Function: Decompress files compressed by compress.

Option:-C. It sends the compressed data to the standard output instead of rewriting the old compressed file.

Explanation: If no file is specified, extract the standard input. The default value is-C, which indicates decompression.

Example: objective: to decompress/mnt/lgx/a1.doc. Z

Command: # uncompress/mnt/lgx/a1.doc. Z

Command: Gzip

Format: gzip option file directory list

Function: Uses Lempel-Ziv encoding to compress files.

Option:-C compression results are written to the standard output, and the original file remains unchanged. When the upload is complete, gzipzip compresses the original file into a. GZ file and deletes the original file.

-V outputs the processing information.

-D. decompress the specified file.

-T to test the integrity of the compressed file.

Note: Gzip is more effective than compress compression.

Example: Objective: To Compress/mnt/lgx/a1.doc

Command: # gzip-V/mnt/lgx/a1.doc

Result: The compressed file named aa1.doc.gz

Command: gunzip

Format: gunzip option file list

Function: Decompress files compressed by gzip commands (and compress and zip commands ).

Option:-C writes the output to the standard output, and the original file remains unchanged. Lack of time, gunzip will convert the compressed file into a decompressed file.

-L list compressed files without decompression.

-R recursive decompression: go deep into the directory structure and decompress the command line to change the files in all subdirectories in the specified directory.

Example: objective: to decompress/mnt/lgx/a1.doc.gz

Command: # gunzip/mnt/lgx/a1.doc.gz

Command: Tar

Format: Tar option file directory list

Function: Package and back up the file directory.

Option:-C. Create a new archive file.

-R: append an object to the end of the archive object

-X solve the file from the archive file

-O unlocks the file to the standard output

-V output related information during processing

-F operations on common files

-Z calls gzip to compress the archive file, and CALLS gzip to decompress the archive file when it is used with-X.

-Z calls compress to compress the archive file, and CALLS compress to decompress the archive file when it is connected to-X.

Example 1: Purpose: To package files in a directory with tar

Command: # tar-CVF/mnt/lgx/a1.doc

Result: A package file with the extension of .tar is created.

Example 2: Purpose: To use tar to unbind a package file

Command: # tar-xvf/mnt/lgx/a1.doc.tar

Additional instructions: In general cases, tar packaging and gzip (compression) are often used together to achieve better results. The method is:

First, use tar for packaging, such as: # tar-CVF/mnt/lgx/a1.doc (a1.doc.tar file)

Then use the gzipcompressed a1.doc.tar file, for example, # gzip/mnt/lgx/a1.doc.tar (424a1.doc.tar.gz file)

Example 3: objective: to decompress the a1.doc.tar.gz File

Method 1:

# Gzip-DC/mnt/lgx/a1.doc.tar.gz (a1.doc.tar file)

# Tar-xvf/mnt/lgx/a1.doc.tar (a1.doc)

These two commands can also use the Pipeline Function to combine the two commands into one:

# Gzip-DC/mnt/lgx/a1.doc.tar.gz | tar-xvf

Method 2: Use the gzip decompression function automatically provided by tar.

# Tar-xzvf/mnt/lgx/a1.doc.tar.gz

After tar packaging, compress can also be compressed using the compress command. Z files, you can first decompress the package in the uncompress file name format, and then use the tar-xvf file name to decompress the package. You can also call "Tar-zxvf file name" to unpack the package.

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.