Tar command details

Source: Internet
Author: User
Tags gz file
Tar command

[[Email protected] ~] #Tar [-cxtzjvfppn] file and folder ....
Number of shards:
-C: Create the sequence number command for a compressed file (create );
-X: number of bytes of a compressed file!
-T: view the files in the tarfile!
Note that C/X/t only exists in the lower limit! Cannot exist at the same time!
Because it is impossible to compress and decompress data at the same time.
-Z: Is gzip attributes available at the same time? Is gzip compression required?
-J: Is the Bzip2 attribute available at the same time? Is it necessary to use Bzip2 for compression?
-V: The file is displayed during compression! This is often used, but it is not recommended to be used in the background running process!
-F: use the file name. Please note that the file name should be followed immediately after F! Do not add more shards!
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: the absolute path 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 folder into/tmp/etc.tar
[[Email protected] ~] #Tar-CVF/tmp/etc.tar/etc<= Package only, not compressed!
[[Email protected] ~] #Tar-zcvf/tmp/etc.tar.gz/etc<= Compressed with gzip After packaging
[[Email protected] ~] #Tar-jcvf/tmp/etc.tar.bz2/etc<= Compressed with Bzip2 After packaging
# Pay special attention to the fact that the file names after the limit number F are obtained by ourselves. We are used to using. tar for identification.
# Assume that the number of Z archives is added, .tar.gz or. tgz is used to represent the tar file ~ compressed by gzip ~
# Assume that the number of J records is added, and .tar.bz2 is used as the appendix name ~
# When running the preceding command, a warning message is displayed:
# "Tar: removing leading '/' from Member names" is a special setting for absolute paths.

Example 2: Check the files in the above/tmp/etc.tar.gz file?
[[Email protected] ~] #Tar-ztvf/tmp/etc.tar.gz
# When we use gzip to compress the files in the TAR file,
# You have to add the Z token number! This is very important!

Example 3: Decompress the/tmp/etc.tar.gz file under/usr/local/src.
[[Email protected] ~] #CD/usr/local/src
[[Email protected] SRC] #Tar-zxvf/tmp/etc.tar.gz
# By default, We Can uncompress the files wherever they are! In this example,
# First, I will transform the working folder to the/usr/local/src directory, and unbind/tmp/etc.tar.gz,
# The unlocked folder will be in/usr/local/src/etc! In addition, assume that you enter/usr/local/src/etc
# The file attributes in this folder may be different from those in/etc!

Example 4: Under/tmp, I just want to unbind 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 use tar-ztvf to check the file name in the tarfile. Assume that only one file is required,
# In this way! Notice! The root folder in etc.tar.gz/is removed!

Example 5: Back up all the files in/etc/and save the permission!
[[Email protected] ~] #Tar-zxvpf/tmp/etc.tar.gz/etc
# This-P attribute is very important, especially when you want to keep the attributes of the original file!

Example 6: In/home, a new file is backed up only when the file is earlier than 2005/06/01.
[[Email protected] ~] #Tar-N '2014/1/01'-zcvf home.tar.gz/home

Example 7: I want to back up/home,/etc, but not/home/dmtsai
[[Email protected] ~] #Tar -- exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc

Example 8: package/etc/and unpack it under/tmp without generating a file!
[[Email protected] ~] #CD/tmp
[[Email protected] TMP] #Tar-CVF-/etc | tar-xvf-
# This action is a bit like CP-r/etc/tmp ~ It still has a real purpose!
# Note that the output file is changed to-and the input file is changed to-, and there is another file | Yes ~
# This represents standard output, standard input, and pipeline commands respectively!
# This part will be explained again when we mention this command in bash shell!

Tar command details

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.