tar command
[Root@linux ~]# tar [-cxtzjvfppn] files and directories ....
Parameters:
-C: Create a compressed file parameter instruction (create meaning);
-x: Unlock a parameter command for a compressed file!
-T: View the files inside the Tarfile!
In particular, in the release of the parameters, c/x/t can only exist one! Not exist at the same time!
Because it is not possible to compress and decompress at the same time.
-Z: Do you have gzip properties at the same time? Is that the need to use gzip compression?
-j: Do you have bzip2 properties at the same time? That is to use bzip2 compression?
-V: Display files during compression! This is commonly used, but is not recommended for use in the background execution process!
-F: Use file name, please note that after F to immediately receive file name Oh! Don't add any more parameters!
For example, the use of "TAR-ZCVFP tfile sfile" is the wrong way to write
"TAR-ZCVPF tfile sfile" is right!
-P: Use the original properties of the original file (properties will not be changed according to the user)
-P: You can use absolute paths to compress!
-N: Newer than the following date (YYYY/MM/DD) will be packaged into the newly created file!
–exclude file: Do not package file in the process of compression!
Example:
Example one: Package all the files in the/etc directory into a/tmp/etc.tar
[Root@linux ~]# tar-cvf/tmp/etc.tar/etc <== only packaged, not compressed!
[Root@linux ~]# tar-zcvf/tmp/etc.tar.gz/etc <== packaged, gzip compressed
[Root@linux ~]# tar-jcvf/tmp/etc.tar.bz2/etc <== after packaging to bzip2 compression
# Note that the file name after the parameter F is taken by itself, and we are accustomed to using the. Tar as an identification.
# If you add the z parameter, the. tar.gz or. tgz to represent the gzip-compressed tar file ~
# If you add the J parameter, use the. tar.bz2 as the file name.
# The above instruction will display a warning message when it is executed:
# "tar:removing leading '/' from member names" That's a special set of absolute paths. Example two: What documents are available in the above/tmp/etc.tar.gz document?
[Root@linux ~]# tar-ztvf/tmp/etc.tar.gz
# Since we use gzip compression, we need to check the files in the tar file
# We're going to have to add the Z parameter! It's very important! Example three: Unzip 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
# in the preset case, we can release the compressed file anywhere! In this example,
# I first transform the working directory underneath the/USR/LOCAL/SRC and unlock the/tmp/etc.tar.gz,
# then untie the catalog will be in/USR/LOCAL/SRC/ETC! In addition, if you enter the/USR/LOCAL/SRC/ETC
# you will find that the file attributes in this directory may be different from the/etc/.
Example four: under/tmp, I just want to untie the etc/passwd in the/tmp/etc.tar.gz.
[Root@linux ~]# Cd/tmp
[Root@linux tmp]# tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can check the file name in the Tarfile through TAR-ZTVF, if only one file
# you can make it through this way! Notice that! The root directory within the etc.tar.gz/was taken away!
Example five: Back up all the files in the/etc/and save their permissions!
[Root@linux ~]# Tar-zxvpf/tmp/etc.tar.gz/etc
# This property of-p is important, especially if you want to preserve the properties of the original file!
Example six: In/home, a new file is backed up in 2005/06/01
[Root@linux ~]# tar-n ' 2005/06/01′-ZCVF home.tar.gz/home
Example seven: I want to back up/home,/etc, but don't/home/dmtsai
[Root@linux ~]# TAR–EXCLUDE/HOME/DMTSAI-ZCVF myfile.tar.gz/home/*/etc
Example eight: The/etc/package will be unpacked directly to the bottom of/tmp, without producing a file!
[Root@linux ~]# Cd/tmp
[Root@linux tmp]# TAR-CVF-/etc | TAR-XVF-
# This action is a bit like cp-r/etc/tmp ~ still has its use!
# The place to notice in the output file becomes-and the input file becomes-, and there's a | exist ~
# This separately represents standard output, standard input and Pipeline command!
# This part we'll be talking about again when we Bash the shell and explain it again!
gzip, Zcat command
[Root@linux ~]# gzip [-cdt#] File name
[Root@linux ~]# zcat file name. gz
Parameters:
-C: Output the compressed data to the screen, can be handled through the data flow redirect;
-D: the extracted parameters;
-T: can be used to verify the consistency of a compressed file ~ To see if there are errors;
-#: Compression level,-1 the fastest, but compression is the worst,-9 slowest, but compression ratio is the best! Preset IS-6 ~
Example:
Example one: Copy/etc/man.config to/tmp and compress with gzip
[Root@linux ~]# Cd/tmp
[Root@linux tmp]# Cp/etc/man.config.
[Root@linux tmp]# gzip Man.config
# now Man.config will turn into man.config.gz! Example two: Read the file contents of sample one!
[Root@linux tmp]# Zcat man.config.gz
# At this time, the screen will show the contents of the file after man.config.gz decompression!!
Example three: Unzip the file of example one
[Root@linux tmp]# gzip-d man.config.gz
Example four: Man.config with the best compression ratio of the example triple untie and keep the original file
[Root@linux tmp]# gzip-9-C man.config > man.config.gz
bzip2, Bzcat command.
[Root@linux ~]# bzip2 [-cdz] File name
[Root@linux ~]# bzcat file name. bz2
Parameters:
-C: Output The compressed process data to the screen!
-D: Uncompressed parameters
-Z: Compressed parameters
-#: The same as gzip, are in the calculation of the compression ratio of the parameters,-9 best,-1 fastest!
Example:
Example one: Compress the/tmp/man.config just to bzip2
[Root@linux tmp]# bzip2-z Man.config
# now Man.config will turn into MAN.CONFIG.BZ2! Example two: Read the file contents of sample one!
[Root@linux tmp]# Bzcat man.config.bz2
# At this time, the screen will show the contents of the file after man.config.bz2 decompression!! Example three: Unzip the file of example one
[Root@linux tmp]# bzip2-d man.config.bz2
Example four: Man.config with the best compression ratio of the example triple untie and keep the original file
[Root@linux tmp]# bzip2-9-C man.config > man.config.bz2
Current 1/2 page
12 Next read the full text