tar command
[Root@linux ~]# tar [-cxtzjvfppn] files and directories ....
Parameters:
-C: Create a compressed file parameter instruction (create meaning);
-X: Unlocks a parameter directive for a compressed file.
-T: View the files inside the tarfile.
In particular, it is noted that c/x/t can only exist in the release of a parameter. Cannot exist at the same time.
Because it is not possible to compress and decompress at the same time.
-Z: Whether to have gzip properties at the same time. That is, whether you need to use gzip compression.
-j: Whether to have bzip2 properties at the same time. That is to use bzip2 compression.
-V: Displays files during compression. This is commonly used, but is not recommended for use in background execution processes.
-F: Use file name, please note that after F to immediately pick up the 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 <== packaged only, 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: Refer to the documents 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
# It's 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 a preset scenario, we can undo the compression file anywhere. In this example,
# I first transform the working directory underneath the/USR/LOCAL/SRC and unlock the/tmp/etc.tar.gz,
# then the unpacked catalogue 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
# It can be done in this way. noticed 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/is packaged and unpacked directly underneath/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 talk about this instruction again when we Bash the shell.
Original link: http://blog.csdn.net/eroswang/article/details/5555415