Syntax: gzip [option] Compress (uncompress) file name the options for this command have the following meanings:
-C writes the output to the standard output and retains the original file. -D Unzip the compressed file. -L Displays the following fields for each compressed file: The size of the compressed file, the size of the uncompressed file, the compression ratio, the name of the uncompressed file-R recursively finds the specified directory and compresses all of its files or is uncompressed. -T test to check that the compressed file is complete. -V displays filename and compression ratio for each compressed and decompressed file. -num adjusts the speed of the compression with the specified number num,-1 or--fast represents the fastest compression method (low compression ratio),-9 or--best represents the slowest compression method (high compression ratio). The default value for the system is 6. Instruction instance:
Gzip *% compresses each file in the current directory into a. gz file. GZIP-DV *% extracts each compressed file in the current directory and lists detailed information. Gzip-l *% details the information for each compressed file in Example 1 and does not understand the pressure. GZIP usr.tar% Compressed tar backup file Usr.tar, at which time the compressed file extension is. tar.gz.
1, Tar
Usage examples
The code is as follows |
Copy Code |
TAR-CF test.tar test.txt This command packs test.txt into a Test.tar file. TAR-ZCF test.tar.gz test.txt This command packs the Test.txt and compresses it into a test.tar.gz file. TAR-RF Test.tar test2.txt This command packs test2.txt into an existing Test.tar file. TAR-TF Test.tar lists the files in the Test.tar package. TAR-XF Test.tar will unlock (somewhat like decompression) Test.tar files. TAR-ZCVF test.tar.gz test.txt and TAR-ZCF test.tar.gz test.txt are similar. Only the command displays the compression process. TAR-ZXVF test.tar.gz will extract the file. |
2, Zip command.
General usage: Zip test.zip test.txt This command automatically packs and compresses test.txt as test.zip files.
The code is as follows |
Copy Code |
Zip-g test.zip test2.txt This command compresses test2.txt into an already existing test.zip. Zip-u test.zip Test.txt checks test.txt for updates and, if the file has changed, compresses the test.txt back into Test.zip. Otherwise, compression is not performed. Zip-d Test.zip Test2.txt will be test.zip, test2.txt deleted. |
3, unzip used to extract the zip file.
General usage. Zip Test.zip decompression Test.zip
Zip Test.zip *.php will extract all the PHP files in Test.zip.
-F Extract only the existing files, other files do not understand the pressure (but the update will be asked).
-U unzip the existing file and unzip the nonexistent file (but will ask for updates).
-fo only extract files that already exist, other files do not understand the pressure (but do not ask for direct overwrite updates).
-uo unzip the existing file and unzip the nonexistent file (without asking for a direct overwrite update).
-O, regardless of whether the file is new or old, is extracted from the compressed file and directly overwritten.
-N extract only nonexistent files, existing files, regardless of the old and new are retained in the original state.
-C Regardless of the case of the different, as the same file name (default is considered different).
-L unzip the file name to lowercase.
Also, processing decisions when you encounter subdirectories:
-j regardless of the original compression of the directory, are all untied in the current directory.
-D followed by a directory name. You can specify the extract to the directory.
One of the other common options:
-L only lists what files are in the package, and does not really unpack the compression.
4, gzip file compression.
Example:
Example one: Package all the files in the/etc directory into a/tmp/etc.tar
The code is as follows |
Copy Code |
[Root@linux ~]# tar-cvf/tmp/etc.tar/etc<== only packaged, not compressed! [Root@linux ~]# tar-zcvf/tmp/etc.tar.gz/etc<== after packaging, gzip compressed [Root@linux ~]# tar-jcvf/tmp/etc.tar.bz2/etc<== after packaging to bzip2 compression |
# Note that the file name after the parameter F is taken by itself, and we are accustomed to using the. Tar as an identification.
# If you add the z parameter, the. tar.gz or. tgz to represent the gzip-compressed tar file ~
# If you add the J parameter, use the. tar.bz2 as the file name.
# The above instruction will display a warning message when it is executed:
# "tar:removing leading"/"from member names" is a special set of absolute paths.
Example two: What documents are available in the above/tmp/etc.tar.gz document?
The code is as follows |
Copy Code |
[Root@linux ~]# tar-ztvf/tmp/etc.tar.gz
|
# Since we use gzip compression, we need to check the files in the tar file
# We're going to have to add the Z parameter! It's very important!
Example three: Unzip the/tmp/etc.tar.gz file under/USR/LOCAL/SRC
The code is as follows |
Copy Code |
[Root@linux ~]# CD/USR/LOCAL/SRC [Root@linux src]# tar-zxvf/tmp/etc.tar.gz # in the preset case, we can release the compressed file anywhere! In this example, # I first transform the working directory underneath the/USR/LOCAL/SRC and unlock the/tmp/etc.tar.gz, # then untie the catalog will be in/USR/LOCAL/SRC/ETC! In addition, if you enter the/USR/LOCAL/SRC/ETC # you will find that the file attributes in this directory may be different from the/etc/. |
Example four: under/tmp, I just want to untie the etc/passwd in the/tmp/etc.tar.gz.
The code is as follows |
Copy Code |
[Root@linux ~]# Cd/tmp [Root@linux tmp]# tar-zxvf/tmp/etc.tar.gz etc/passwd
|
# I can check the file name in the Tarfile through TAR-ZTVF, if only one file
# you can make it through this way! Notice that! The root directory within the etc.tar.gz/was taken away!
Example five: Back up all the files in the/etc/and save their permissions!
The code is as follows |
Copy Code |
[Root@linux ~]# Tar-zxvpf/tmp/etc.tar.gz/etc
|
# This property of-p is important, especially if you want to preserve the properties of the original file!
Example six: In/home, a new file is backed up in 2005/06/01
The code is as follows |
Copy Code |
[Root@linux ~]# tar-n "2005/06/01"-ZCVF home.tar.gz/home |
Example seven: I want to back up/home,/etc, but don't/home/dmtsai
The code is as follows |
Copy Code |
[Root@linux ~]# tar--exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc |
Example eight: The/etc/package will be unpacked directly to the bottom of/tmp, without producing a file!
The code is as follows |
Copy Code |
[Root@linux ~]# Cd/tmp [Root@linux tmp]# TAR-CVF-/etc | TAR-XVF-
|
# This action is a bit like cp-r/etc/tmp ~ still has its use!
# The place to notice in the output file becomes-and the input file becomes-, and there's a | exist ~
# This separately represents standard output, standard input and Pipeline command!
# This part we'll be in Bash shell,