Linux decompression command explanation
Author: Egg
Email: xtfggef@gmail.com
Weibo: http://weibo.com/xtfggef
Blog: http://blog.csdn.net/zhangerqing
These commands are very common and need to be kept in mind. Let's simply summarize them:
Tar [-cxtzjvfppn] file and directory ....
Parameters:
-C: Create a parameter command for the compressed file
-X: Unlock the parameter commands of a compressed file
-T: view the files in the compressed file
Note: C/X/T can only exist at the same time, because it is impossible for us to compress and decompress at the same time.
-Z: does it have the gzip attribute at the same time? Whether gzip compression is required
-J: Does it have Bzip2 attributes at the same time? That is, whether Bzip2 compression is required
-V: The file is displayed during compression! This is commonly used, but is not recommended for background execution.
-F: use the file name. Please note that the file name should be followed immediately after F! Do not add Parameters
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: absolute paths 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 directory into/tmp/etc.tar
[Root @ Linux ~] # Tar-CVF/tmp/etc.tar/etc <= package only, do not compress!
[Root @ Linux ~] # Tar-zcvf/tmp/etc.tar.gz/etc <= compressed with Gzip
[Root @ Linux ~] # Tar-jcvf/tmp/etc.tar.bz2/etc <= compressed with Bzip2
# 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 ~
# A warning message is displayed when the preceding command is executed:
# "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?
[Root @ Linux ~] # Tar-ztvf/tmp/etc.tar.gz
# When we use gzip to compress the files in the TAR file,
# 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, I will transform 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
# 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 you only need one file,
# You 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-zcvpf/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-
# This action is a bit like CP-r/etc/tmp ~ It is still useful!
# 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!
Common compression and decompression commands:
Suffix. Tar
Unzip the command: Tar xvf infile.tar
Compression command: Tar CVF outfile.tar infile
Compressed file type: folder
Suffix .tar.gz
Unzip the command: Tar zxvf infile.tar.gz
Compression command: Tar zcvf outfile.tar.gz infile
Compressed file type: folder
Suffix .tar.bz2
Unzip the command: Tar jxvf infile.tar.bz2
Compression command: Tar jcvf outfile.tar.bz2 infile
Compressed file type: folder
Suffix. Tar. Z
Unzip the command: Tar zxvf infile.tar. Z
Compression command: Tar zcvf outfile.tar. Z infile
Compressed file type: folder
Suffix. GZ
Decompress the command: gzip-D infile.gz or gunzip infile.gz
Compression command: gzip infile
File type that can be compressed: Common File/package file
Suffix. Zip
Unzip the command: unzip infile.zip
Compression command: Zip outfile.zip infile
File type that can be compressed: common file list/package file
Suffix. bz2
Decompress the command: Bzip2-D infile.bz2 or bunzip2 infile.bz2
Compression command: Bzip2-Z infile
File type that can be compressed: Common File/package file
Suffix. Z
Decompress the command: uncompress infile. Z
Compression command: compress infile
Compressed file type: package file
Suffix. rar
Unzip the command: RAR x infile.rar
Compression command: rar a infile
File type that can be compressed: Folder/common file list/package file
Some of the content in this article comes from the internet. I will summarize it myself and add my own things. If there is any infringement, please contact me and be sure to actively handle it!