1. gzip, zcat [root @ linux ~] # Gzip [-cdt #]? N parameters:-c: output compressed data to the screen, which can be processed through data stream redirection;-d: extracted parameters;-t: it can be used to check the consistency of a compressed file ~ Check whether the file has any errors.-#: compression level ,-
1. gzip, zcat
[Root @ linux ~] # Gzip [-cdt #]? N
Parameters:
-C: outputs compressed data to the screen and can be processed through data stream redirection;
-D: extract parameters;
-T: It can be used to check the consistency of a compressed file ~ Check whether the file has any errors;
-#: Compression level.-1 is the fastest, but the compression ratio is the worst.-9 is the slowest, but the compression ratio is the best! Default value:-6 ~
Zcat is a command used to read compressed file data.
[Root @ linux ~] # Zcat? Nname.gz
Example:
Example 1: Copy/etc/man. config to/tmp and compress it with gzip
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # cp/etc/man. config.
[Root @ linux tmp] # gzip man. config
# At this time, man. config will become man.config.gz!
Example 2: read the file content of Example 1!
[Root @ linux tmp] # zcat man.config.gz
# The man.config.gz extracted file content is displayed on the screen !!
Example 3: extract the archive of Example 1
[Root @ linux tmp] # gzip-d man.config.gz
Example 4: compress man. config unlocked in example 3 with the optimal compression ratio and keep the original file
[Root @ linux tmp] # gzip-9-c man. config> man.config.gz
2.bzip2, bzcat
[Root @ linux ~] # Bzip2 [-cdz]? N
[Root @ linux ~] # Bzcat? Nname.bz2
Parameters:
-C: output the data generated during the compression process to the screen!
-D: extracted parameters
-Z: compression parameters
-#: Same as gzip, it is used to calculate the compression ratio.-9 is the best, and-1 is the fastest!
Example:
Example 1: compress/tmp/man. config with bzip2
[Root @ linux tmp] # bzip2-z man. config
# At this time, man. config will become man.config.bz2!
Example 2: read the file content of Example 1!
[Root @ linux tmp] # bzcat man.config.bz2
# The man.config.bz2 extracted file content is displayed on the screen !!
Example 3: extract the archive of Example 1
[Root @ linux tmp] # bzip2-d man.config.bz2
Example 4: compress man. config unlocked in example 3 with the optimal compression ratio and keep the original file
[Root @ linux tmp] # bzip2-9-c man. config> man.config.bz2
3. tar
[Root @ linux ~] # Tar [-cxtzjvfpPN] files and directories ....
Parameters:
-C: create a file compression parameter command (create );
-X: command to uncompress a 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 attribute of the original file (the attribute will not be changed based on the user)
-P: absolute paths can be used for compression!
-N: it is newer than the subsequent date (yyyy/mm/dd) to be packaged into the new file!
-- Exclude FILE: Do not pack the FILE during compression!
Example:
Example 1: Package all 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:
# "Tar: Removing leading '/' from member names" is a special setting about absolute paths.
Example 2: Check the files in the/tmp/etc.tar.gz file?
[Root @ linux ~] # Tar-ztvf/tmp/etc.tar.gz
# Since we use gzip compression, when you want to view the files in the tar file,
# Add the z parameter! This is important!
Example 3: decompress the/tmp/etc.tar.gz file under/usr/local/src.
[Root @ linux ~] # Cd/usr/local/src
[Root @ linux src] # tar-zxvf/tmp/etc.tar.gz
# By default, we can uncompress files anywhere! In this example,
# First, I will transform the working directory to the/usr/local/src directory, and unlock/tmp/etc.tar.gz,
# The unlocked directory will be in/usr/local/src/etc! In addition, if you enter/usr/local/src/etc
# The File attributes in this directory may be different from those in/etc!
Example 4: Under/tmp, I only want to unbind the etc/passwd in/tmp/etc.tar.gz.
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can use tar-ztvf to check the file name in the tarfile. if you only need one file,
# You can issue it in this way! Notice! The root directory in etc.tar.gz/is removed!
Example 5: Back up all files in/etc/and save their permissions!
[Root @ linux ~] # Tar-zcvpf/tmp/etc.tar.gz/etc
# This-p attribute is very important, especially when you want to keep the attribute of the original file!
Example 6: only new files in/home are backed up.
[Root @ linux ~] # Tar-N '2014/1/01'-zcvf home.tar.gz/home
Example 7: I want to back up/home,/etc, but not/home/dmtsai
[Root @ linux ~] # Tar -- exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc
Example 8: Package/etc/and unpack it under/tmp without generating an archive!
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # tar-cvf-/etc | tar-xvf-
# This action is a bit like cp-r/etc/tmp ~ It is still useful!
# Note that the output file is changed to-, the input file is also changed to-, and there is another | yes ~
# This represents standard output, standard input, and pipeline commands respectively!