File compression and packaging in linux --- compress, gzip, zcat, bzip2, bzcat, tar, find, tarfile, tarball

Source: Internet
Author: User
Tags uncompress

File compression and packaging in linux --- compress, gzip, zcat, bzip2, bzcat, tar, find, tarfile, tarball
Common Linux compressed file extensions

*. Z compress compressed files (replaced by gzip)

*. Gz gzip compressed files

*. Bz2 bzip2 compressed files (better than gzip, but only one file can be compressed)

* The data packaged by the. tar program is not compressed (using tar as a file can solve the problem that bzip2 cannot compress multiple files)

* .Tar.gz tar package data, compressed by gzip

* .Tar.bz2 tar package data, which is compressed by bzip2

Compress uses the ubuntu installation command:

Apt-get install compress

Operation Command:

After the command is executed, the target file is replaced.

Compress [-rcv] File Name or directory name

Decompress uncompress file name. z

Execute commands without replacing the target file

Compress-c target file name> New File Name

Main parameters:

-R: compress the files in the connected directory.

-C: output the compressed data to the screen (without actual compression)

-V: output the compressed file information and file changes (without actual compression)

Use of gzip and zcat

Gzip can be used to uncompress, zip, and gzip files. The compression file extension is gz.

Operation Command:

Gzip [-cdtv #] File Name or directory name

Zcat file name .gz does not need to be decompressed to output compressed file content on the screen

Execute commands without replacing the target file

Gzip-c target file name> New File Name

Gizp-d target file name> New File Name

Main parameters:

-C: Output compressed data to the screen

-D: extracted Parameters

-T: used to check the consistency of a compressed file to see if there are any errors.

-V: displays the compression ratio of the original file/compressed file.

-#: Compression level.-1 is the fastest and-9 is the slowest. The default value is-6. The speed is inversely proportional to the compression ratio.

Gunzip is also a decompression command

Bzip2 and bzcat commands:

Bzip2 [-cdkzv #] File Name

Bzcat file name .bz2

Main parameters:

-C: output the compressed data to the screen.

-D: extract parameters.

-K: keep the original file and do not delete the original file.

-Z: Compression Parameters

-V: displays the compression ratio of the original file/compressed file.

-V: Same as gzip

The bunzip2 command can also be used for decompression.

Packaging command: tar operation command:

Packaging and compression: tar [-j |-z] [cv] [-f file name]

View the file: tar [-j |-z] [TV] [-f file name]

Decompress: tar [-j |-z] [xv] [-f file name] [-c Directory]

Main parameters:

-C: Create a package file. You can use-v to view the packaged file name.

-T: view the files contained in the package.

-X: Decompress or decompress the package. It can be used with-C (uppercase) to unbind the package in a specific directory.-c,-t, and-x cannot appear in a string of commands at the same time.

-J: Use bzip2 to compress or decompress the file. The file name is * .tar.bz2.

-Z: Compressed or decompressed using gzip. The file name is * .tar.gz.

-V: displays the file name being processed during compression/decompression.

-F filename: the name of the file to be processed immediately after-f

-C Directory: This option is used for decompression. You can use this option to decompress the package in a specific directory.

-P: (lower case p) retains the original permissions and attributes of the backup data. It is usually used to back up important configuration files, which are very important parameters.

-P: (uppercase P) retains the absolute path, allowing the backup data to contain the root directory

-- Exclude = FILE: Do not package the FILE during compression.

Tip: extract a single file in the package

Tar-jtv-f directory/file name .tar.bz2 | grep 'query string'

Grep is a keyword search function. After finding the target directory

Tar-jxv-f package file name .tar.bz2 unbind the target directory

How to package a directory but not some files in the directory

Tar-jcv-f/root/etc.tar.bz2 -- exclude =/root/etc *> -- exclude =/root/etc.tar.bz2/etc/root

Only back up new files than at a certain time

-- Newer option and -- newer-mtime

-- Newer indicates that mtime and ctime are followed

-- Newer-mtime is only mtime

Use find/etc-newer/etc/passwd to find the new file.

Time for finding a target file

Tar-jcv-f/root/etc.tar.bz2> -- newer-mtime = "2011/10/3"/etc /*

Tarfile, tarballtarfile

Only use the tar command to package files that are not compressed

Tarball

Files packaged and compressed using the tar command

How to Use the tar command to be assigned to the drive/dev/st0

Tar-cv-f/dev/st0/home/root/etc

Using pipeline commands and data stream backup

Is to package and decompress the package to the target directory.

Cd/tmp

Tar-cvf-/etc | tar-xvf-

That is, copy the data under/etc directly to the directory path under/tmp.

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.