This original article belongs to the "Linux Greenhouse" blog.
The blog address is http://roclinux.cn.
Article author for Roc
I hope you can donate to support the operation and development of the Linux greenhouse blog. See "About Donations"
==
The big pain after moving to Linux is compression and decompression, and today's theme is "Compression and decompression tool gzip".
Five minutes to teach you Linux compression and decompression Dafa ~ ~
1 downloaded a source file abc.tar.gz or abc.tgz (suffix tar.gz and tgz basically no difference, the same also. Taz and. Tar.z)
# TAR-XZVF abc.tar.gz or
# TAR-XZVF Abc.tgz
Comments:
Tar.gz and tgz are compressed packages that have been archived and compressed by the Gzip tool.
The x option indicates that the decompression
Z means unzip with the Gzip tool
V indicates that details are displayed when decompressed
F indicates the specified file (note that this option must be placed at the end of each option--that is, the closest you have to the file name you specified)
2 encountered a file xyz.gz, want to decompress:
# gzip-d Xyz.gz
Note: The D option indicates that the decompression
3 encountered a file Edf.tar, want to extract: (Strictly speaking the tar file is an archive file, not compressed, the "decompression" mentioned here just to take the tar file apart):
# TAR-XVF Edf.tar
Note: In fact, this command is not a compression command category, just mention here:)
4 you want to compress a folder dirabc into a. tar.gz compressed file:
# TAR-CZVF dirabc.tar.gz DIRABC
5 want to see what files are included in the downloaded abc.tar.gz zip file
# TAR-ZTVF Abc.tar.gz
6 Use 5 method to view the abc.tar.gz compressed package, including def/xyz.txt files and many other files, but only want to extract xyz.txt this one file
# TAR-XZVF abc.tar.gz Def/xyz.txt
7 Decompression abc.tar.gz I want to keep the original compressed file permissions (often used for backup)
# TAR-XZVPF Abc.tar.gz
8 I want to compress the fastest, the price is the highest compression ratio
# gzip-1 Abc.tar
Note: 1 can also be converted to –fast;-9 to indicate compression ratio, but the slowest, 9 can also be replaced with –best. The default is-6 (the number is not good to remember, you can remember: 1 means one step, often one step things to pursue is fast, rather than the degree of refinement ^_^)
Summarize the options for the tar:
-X: Unpacking Instructions
-C: Packaging instructions
-T: View package Instructions
X,c,t can only exist one, cannot exist a common decompression command
-Z: File with gzip decompression
-J: File with bzip2 decompression
-V: View the decompression process
-F: The command parameter is then followed by the file name (the file name to be extracted) or the folder name (compressing the folder)
-P: Retains the original owner of the file
The tar command is actually a packaged command that packages multiple files into one file because the compression command can only be a file, not a folder or multiple files
- P : You can use absolute path to compress!
-N : Newer than next date (YYYY/MM/DD) will be packaged in the new file!
--exclude file: In the process of compression, do not package file !
Example:
Example one: Will the whole /etc The files in the directory are all packaged as /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, take the gzip Compression
[email protected] ~]# tar-jcvf/tmp/etc.tar.bz2/etc <== after packing, take bzip2 Compression
# in particular, the parameter F after the file name is taken by themselves, we used to use . Tar for identification.
# If you add z parameter, the . tar.gz or . tgz to represent gzip compressed tar file ~
# If you add J parameter, the . tar.bz2 For the name of the file.
# When the above instruction is executed, a warning message is displayed:
# "tar:removing leading '/" from member names "That's a special setting for absolute paths.
Example Two: Check the above /tmp/etc.tar.gz what files are in the file?
[Email protected] ~]#
tar-ztvf/tmp/etc.tar.gz
# Since we use gzip compressed, so check the tar file within the file,
# You have to add z . This parameter is up! It's important! example three: Will /tmp/etc.tar.gz file decompression in /usr/local/src underneath
[Email protected] ~]#
cd/usr/local/src
[Email protected] src]#
tar-zxvf/tmp/etc.tar.gz
# in the case of a preset, we can unzip the file anywhere! In the case of this example,
# I'll start by transforming the working directory to /USR/LOCAL/SRC . underneath, and untie /tmp/etc.tar.gz ,
# then the unpacked directory will be in the /usr/local/src/etc it! Also, if you enter /usr/local/src/etc
# you will find that the file attributes in this directory and the /etc/ It may be different oh! example four: In/ tmp underneath, I just want to /tmp/etc.tar.gz inside the etc/passwd Just untie it.
[Email protected] ~]#
cd/tmp
[Email protected] tmp]#
tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can get through TAR-ZTVF . to check out tarfile within the file name, if only one file is single,
# It can be released in this way! Notice that! etc.tar.gz within the root directory / it was taken away! Example five: Will /etc/ back up all the files in the file and save their permissions!
[Email protected] ~]#
tar-zxvpf/tmp/etc.tar.gz/etc
# this- p properties are important, especially if you want to preserve the properties of the original file! example six: at / Home among them, than 2005/06/01 new files are not backed up
[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: Will /etc/ Unpacking directly in/ tmp underneath, without producing files!
[Email protected] ~]#
cd/tmp
[Email protected] tmp]#
TAR-CVF-etc | tar-xvf-
# It's kind of like a cp-r/etc/tmp . There is still a use for it!
# The point to note is that the output file becomes - and the input file also becomes - , there is another one | exist ~
# this represents standard output and standard input, respectively. with the pipeline command!
gzip Command-linux command five-minute series seven