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

Source: Internet
Author: User
Tags uncompress

File compression and packaging in linux --- compress, gzip, zcat, bzip2, bzcat, tar, find, tarfile, tarball, --- compresszcat
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.


In Linux, how does one decompress a specified file in a compressed file using the command line?

Tar [-cxtzjvfpPN] file and directory ....
Parameters:
-C: create a parameter command for the compressed file );
-X: Unlock the parameter command of a compressed file!
-T: view the files in the tarfile!
Note that c/x/t can only exist under the parameter! Cannot exist at the same time!
Because it is impossible to simultaneously compress and decompress.
-Z: does it have the gzip attribute at the same time? That is, do I need to use gzip for compression?
-J: Does it have bzip2 attributes at the same time? That is, do I need to use bzip2 for compression?
-V: The file is displayed during compression! This is common, but it is not recommended to use it in the background execution process!
-F: use the file name. Please note that the file name should be followed immediately after f! Do not add parameters!
For example, using "tar-zcvfP tfile sfile" is an incorrect method.
"Tar-zcvPf tfile sfile" is correct!
-P: use the original attributes of the original file (the attributes will not be changed based on the user)
-P: absolute paths can be used for compression!
-N: a new date (yyyy/mm/dd) will be packed into the new file!
-- Exclude FILE: do not pack the FILE during compression!

Statement: tar file.tar-x a.txt

Tar-czvf 20100110tgz wwwroot in LINUX

Tar command

Tar [-cxtzjvfpPN] file and directory ....

Parameters:
-C: create a parameter command for the compressed file );
-X: Unlock the parameter command of a compressed file!
-T: view the files in the tarfile!
Note that c/x/t can only exist under the parameter! Cannot exist at the same time!
Because it is impossible to simultaneously compress and decompress.
-Z: does it have the gzip attribute at the same time? That is, do I need to use gzip for compression?
-J: Does it have bzip2 attributes at the same time? That is, do I need to use bzip2 for compression?
-V: The file is displayed during compression! This is common, but it is not recommended to use it in the background execution process!
-F: use the file name. Please note that the file name should be followed immediately after f! Do not add parameters!
For example, using "tar-zcvfP tfile sfile" is an incorrect method.
"Tar-zcvPf tfile sfile" is correct!
-P: use the original attributes of the original file (the attributes will not be changed based on the user)
-P: absolute paths can be used for compression!
-N: a new date (yyyy/mm/dd) will be packed into the new file!
-- Exclude FILE: do not pack the FILE during compression!
Example:
Example 1: package all the files in the/etc directory into/tmp/etc.tar
[Root @ linux ~] # Tar-cvf/tmp/etc.tar/etc <= package only, do not compress!
[Root @ linux ~] # Tar-zcvf/tmp/etc.tar.gz/etc <= compressed with gzip
[Root @ linux ~] # Tar-jcvf/tmp/etc.tar.bz2/etc <= compressed with bzip2
# Note that the file name after parameter f is obtained by ourselves. We use. tar for identification.
# If the z parameter is added, .tar.gz or. tgz is used to represent the tar file ~ compressed by gzip ~
# If you add the j parameter, use .tar.bz2 as the file name ~
# A warning message is displayed when the preceding command is executed:

In addition, we recommend that you have all the details of the tar command in 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.