ArticleDirectory
- Unzip the tar command in Linux
Unzip the tar command in Linux
Tar command
Tar [-cxtzjvfppn] file and directory ....
Parameter:-C: Create a compressed file parameter command (create);-X: unlock a compressed file parameter command! -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, if you use "Tar-zcvfp tfile sfile", it is wrong to write it as "Tar-zcvpf tfile sfile! -P: use the original attributes of the original file (the attributes will not be changed based on the user)-P: You can use absolute paths to compress!
-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 directory into/tmp/etc.tar [Root @ Linux ~] # Tar-CVF/tmp/etc.tar/etc <= Package only, not compressed! [Root @ Linux ~] # Tar-zcvf/tmp/etc.tar.gz/etc <= Compressed with gzip After packaging [Root @ Linux ~] # Tar-jcvf/tmp/etc.tar.bz2/etc <= Compressed with Bzip2 After packaging # 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 ~ # When the preceding command is executed, a warning message is displayed: # "Tar: removing leading '/" from Member names ", which is a special setting for absolute paths.
Example 2: Check the files in the above/tmp/etc.tar.gz file?
[Root @ Linux ~] #Tar-ztvf/tmp/etc.tar.gz # Because Gzip is used for compression, when you want to view the files in the TAR file, # You have to 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 change 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 #, you will find that 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 only one file is required, # I can issue it in this way! Notice! The root directory in etc.tar.gz/is removed!
Example 5: Back up all the files in/etc/and save their permissions!
[Root @ Linux ~] #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: only new files in/home are backed up.
[Root @ Linux ~] #Tar-n "2005/06/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 a file!
[Root @ Linux ~] #CD/tmp
[Root @ Linux TMP] #Tar-CVF-/etc | tar-xvf-