A detailed description of the tar command

Source: Internet
Author: User

Tar command

[[email protected] ~]# tar [-cxtzjvfppn] files and folders ....
Number of references:
-C: Create an instruction for a compressed file (the meaning of Create);
-x: Unlock the parameters of a compressed file!
-T: View the files inside the Tarfile!
In particular, the c/x/t can only exist in the release of the number of participants! Do not exist at the same time!
Because it is not possible to compress and decompress at the same time.
-Z: Is there a property with gzip at the same time? Is gzip compression required?
-j: Do you have bzip2 properties at the same time? i.e. is it necessary to compress with bzip2?
-V: Files are displayed during compression! This is often used, but it is not recommended to run the process in the background!
-F: Use the file name, please note that after f you have to answer the file name! Don't add a few more!
For example, the use of "TAR-ZCVFP tfile sfile" is the wrong way to write
"TAR-ZCVPF tfile sfile" Just right!
-P: Using the original file's original properties (attributes are not changed according to the user)
-P: Can use absolute path to compress!
-N: Newer than next date (YYYY/MM/DD) will be packaged into the new file!
--exclude file: In the process of compression, do not package file!


Example:
Example One: package all files under the whole/etc folder into/tmp/etc.tar
[Email protected] ~]#tar-cvf/tmp/etc.tar/etc <== package only, do not compress!
[Email protected] ~]#tar-zcvf/tmp/etc.tar.gz/etc <== after packaging, compress with gzip
[Email protected] ~]#tar-jcvf/tmp/etc.tar.bz2/etc <== after packing, compress with bzip2
# Note that the file names after the number F are taken by themselves, and we are accustomed to using. Tar as an identification.
# assuming a z-parameter, the. tar.gz or. tgz represent gzip compressed tar file ~
# Assuming the addition of J, then use. tar.bz2 as the file name.
# When the above instruction is running, a warning message is displayed:
# "tar:removing leading '/' from member names" That's a special setting for absolute paths .

Example two: Check out what files are in the above/tmp/etc.tar.gz file?
[Email protected] ~]# tar-ztvf/tmp/etc.tar.gz
# because we use gzip compression, so to check the file in the tar file,
# you have to add Z to this number! It's very important!

example three: Extract/tmp/etc.tar.gz files under/usr/local/src
[[email protected] ~ ]# cd/usr/local/src
[[email protected] Src]# tar-zxvf/tmp/etc.tar.gz
# in a preset situation, we are able to unpack the archive anywhere! In this example,
# I first transform the working folder under/usr/local/src, and Untie/tmp/etc.tar.gz,
# then the unpacked folder will be/USR/LOCAL/SRC/ETC! Also, if you enter/usr/local/src/etc
#, you will find that the file properties under this folder may be different from/etc/.

Example four: under/tmp, I just want to untie the etc/passwd in/tmp/etc.tar.gz.
[Email protected] ~]# cd/tmp
[Email protected] tmp]# tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can look through the TAR-ZTVF to see the file name inside the tarfile, assuming only one file is needed,
# can be released in this way! Notice that! The root folder within the etc.tar.gz/is taken away!

Example five: Back up all the files in the/etc/, and save their permissions!
[Email protected] ~]# tar-zxvpf/tmp/etc.tar.gz/etc
# The properties of this-p are very important, especially if you want to keep the properties of the original file!

Example six: In/home where the new files are backed up than in 2005/06/01
[Email protected] ~]# tar-n ' 2005/06/01 '-zcvf home.tar.gz/home

Example seven: I want to back up/home, etc, but don't/home/dmtsai
[Email protected] ~]# tar--exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc

Example eight: Unpack the/etc/directly under/TMP without generating files!
[Email protected] ~]# cd/tmp
[Email protected] tmp]# TAR-CVF-etc | tar-xvf-
# This action is a bit like a cp-r/etc/tmp ~ still has a de facto use!
Note that the output file becomes-and the input file becomes-and another | exist ~
# This represents the standard output, the standard input and the pipeline command!
# This part we'll be talking about this command again in Bash Shell and explain it to everyone!

A detailed description of the tar command

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.