How to unzip a. GZ zip file

Source: Internet
Author: User
Tags bz2 gz file rar zip
how to unzip a. gz zip file

#gzip-D xxx.gz

Tar command
[Root@linux ~]# tar [-cxtzjvfppn] files and directories ....
-C: Create a compressed file parameter directive (the meaning of Create);
-X: Unlocks a parameter directive for a compressed file.
-T: View the files inside the tarfile.
In particular, the c/x/t can only exist in the release of a parameter. Cannot exist simultaneously.
Because it is not possible to compress and decompress simultaneously.
-Z: Whether to have gzip properties at the same time. i.e. whether gzip compression is required.
-J: Whether you have bzip2 properties at the same time. That is, if you need to compress with bzip2.
-V: The file is displayed during compression. This is commonly used, but is not recommended for use in the background execution process.
-F: Use the file name, please note, after F to immediately answer the file name Oh. Do not add arguments.
For example, using "TAR-ZCVFP tfile sfile" is the wrong way to write
"TAR-ZCVPF tfile sfile" was right.
-P: Use original file properties (attributes are not changed according to user)
-P: The absolute path can be used to compress.
-N: Newer than the later date (YYYY/MM/DD) will be packaged into the new file.
--exclude file: Do not package file in the process of compression.
Example one: Package all the files in the/etc directory into/tmp/etc.tar
[Root@linux ~]# tar-cvf/tmp/etc.tar/etc <== packaged only, not compressed.
[Root@linux ~]# tar-zcvf/tmp/etc.tar.gz/etc <== packaged, compressed with gzip
[Root@linux ~]# tar-jcvf/tmp/etc.tar.bz2/etc <== packed, compressed with bzip2
# Note that the file name after parameter f is taken by yourself, and we are accustomed to using. Tar as a recognition.
# if the z parameter is added, the. tar.gz or. tgz represent the gzip compressed tar file ~
# If you add the J parameter, use. tar.bz2 as the file name.
# 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 out which files are in the/tmp/etc.tar.gz file above.
[Root@linux ~]# tar-ztvf/tmp/etc.tar.gz
# because we use gzip compression, so to check the file in the tar file,
# you have to add Z to this parameter. It's very important.

Example three: Extracting 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
# in the case of presets, we can unzip the file anywhere. In the case of this example,
# I'm going to transform my working directory under/USR/LOCAL/SRC and untie/tmp/etc.tar.gz,
# then the unpacked catalogue will be in/USR/LOCAL/SRC/ETC. Also, if you enter/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 inside the/tmp/etc.tar.gz.
[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/is taken away.

Example five: Back up all files within the/etc/and save their permissions.
[Root@linux ~]# Tar-zxvpf/tmp/etc.tar.gz/etc
# The properties of this-p are important, especially if you want to preserve the properties of the original file.

Example six: In/home, more than 2005/06/01 new files are backed up
[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
[Root@linux ~]# tar--exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc

Example eight: The/etc/is packaged and unpacked directly 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 ~ still has its use.
Note that the output file becomes-and the input file becomes-and another | exist ~
# This represents the standard output, the standard input, and the pipeline command, respectively.
# This part we'll be talking about this command again in Bash Shell and then we'll explain again.

gzip, Zcat command
[Root@linux ~]# gzip [-cdt#] File name
[Root@linux ~]# zcat file name. gz
-C: The compressed data output to the screen, can be processed through data flow redirection;
-D: the extracted parameters;
-T: can be used to verify the consistency of a compressed file ~ See if there are errors;
-#: Compression level, 1 the fastest, but the worst compression ratio,-9 slowest, but the best compression. The preset is-6 ~
Example one:/etc/man.config is copied to/TMP and compressed with gzip
[Root@linux ~]# Cd/tmp
[Root@linux tmp]# Cp/etc/man.config.
[Root@linux tmp]# gzip Man.config
# at this time Man.config will become man.config.gz.
Example two: Read the file contents of example one.
[Root@linux tmp]# Zcat man.config.gz
# The contents of the file after man.config.gz decompression will be displayed on the screen.

Example three: Extracting a file from sample one
[Root@linux tmp]# gzip-d man.config.gz

Example four: Man.config with the best compression ratio and retains the original file
[Root@linux tmp]# gzip-9-C man.config > man.config.gz

bzip2, Bzcat command
[Root@linux ~]# bzip2 [-cdz] File name
[Root@linux ~]# bzcat file name. bz2
-C: Outputs the data generated by the compression process to the screen.
-D: decompressed parameters
-Z: Compressed parameters
-#: Same as gzip, all in the calculation of compression ratio parameters,-9 best,-1 fastest.
Example one: Compress just the/tmp/man.config with bzip2
[Root@linux tmp]# bzip2-z Man.config
# at this time Man.config will become man.config.bz2.
Example two: Read the file contents of example one.
[Root@linux tmp]# Bzcat man.config.bz2
# The contents of the file after man.config.bz2 decompression will be displayed on the screen.

Example three: Extracting a file from sample one
[Root@linux tmp]# bzip2-d man.config.bz2

Example four: Man.config with the best compression ratio and retains the original file
[Root@linux tmp]# bzip2-9-C man.config > man.config.bz2

Compress command
[Root@linux ~]# compress [-DCR] file or directory
-D: Parameters to decompress
-R: It can also be compressed together with the files in the directory.
-C: Output compressed data to standard output (outputs to screen)
Example one:/etc/man.config is copied to/TMP and compressed
[Root@linux ~]# Cd/tmp
[Root@linux tmp]# Cp/etc/man.config.
[Root@linux tmp]# Compress Man.config
[Root@linux tmp]# Ls-l
-rw-r--r--1 root root 2605 Jul 11:43 man.config.z
Example two: Unlock the zip file you just got
[Root@linux tmp]# compress-d man.config.z

Example three: compressing the man.config into another file to back up
[Root@linux tmp]# compress-c man.config > Man.config.back.z
[Root@linux tmp]# ll man.config*
-rw-r--r--1 root root 4506 Jul 11:43 man.config
-rw-r--r--1 root root 2605 Jul 11:46 man.config.back.z
# The parameters of this-C are more interesting. He will output the data from the compression process to the screen instead of writing it into
# file. Z file. Therefore, we can export the data to another file name through a data flow redirection method.
# for Data flow redirection, we'll talk more about it in bash shell.

DD command
[Root@linux ~]# dd if= "input_file" of= "Outptu_file" bs= "Block_size" \
count= "Number"
If: It is the input file or it can be a device oh.
Of: is output file Oh ~ can also be a device;
BS: Plan the size of a block, if not set, the preset is bytes
Count: How many BS means.
Example one: Backup/etc/passwd to/tmp/passwd.back
[Root@linux ~]# DD if=/etc/passwd of=/tmp/passwd.back
3+1 Records in
3+1 Records out
[Root@linux ~]# Ll/etc/passwd/tmp/passwd.back
-rw-r--r--1 root root 1746 14:16/etc/passwd
-rw-r--r--1 root root 1746 16:57/tmp/passwd.back
# Take a closer look, my/etc/passwd file size is 1746 bytes, because I didn't set BS,
# So the preset is bytes to a unit, so the above 3+1 says there are 3 complete
# bytes, and the meaning of another block that is not full of bytes.
# In fact, it feels like the CP command ~

Example two: Backing up the/dev/hda MBR
[Root@linux ~]# dd If=/dev/hda of=/tmp/mbr.back bs=512 count=1
1+0 Records in
1+0 Records out
# It's got to be understood # We know the MBR of the whole hard disk is bytes,
# is the first sector on the hard drive, so I can use this way to
# All the information in the MBR is recorded, really very powerful. ^_^

Example three: Back up the entire/DEV/HDA1 partition.
[Root@linux ~]# DD if=/dev/hda1 OF=/SOME/PATH/FILENAEM
# This is a very powerful command. Back up all the content of the entire partition ~
# The latter must not be in the/dev/hda1 of the directory Ah ~ Otherwise, how to read also can not finish ~
# This action is very effective, if you have to complete the whole partition of the contents of a day to fill back,
# You can use DD If=/some/file of=/dev/hda1 to write data to the hard disk.
# If you want an entire hard disk backup, like Norton's Ghost software in general,
# from disk to disk, hehe ~ To use DD can ~ very bad.

Cpio command
[Root@linux ~]# cpio-covb > [file|device] <== Backup
[Root@linux ~]# Cpio-icduv < [file|device] <== Restore
-o: Data copy output to a file or device
-I: Copy data from file or device to system
-T: View the contents of a file or device created by Cpio
-C: A newer portable format mode storage
-V: Allows the file name to be displayed on the screen during storage
-B: Allows the preset Blocks to be increased to 5120 bytes, which is a preset of bytes.
The benefit is that large files can be stored faster (refer to the I-nodes concept)
-D: Automatically create a directory. Because the content of cpio may not be in the same directory,
In this case, there will be a problem with the anti-backup process. Add-D to this time,
You can automatically set up the required directories.
-U: Automatically overwrites newer files with older ones.
Example one: All data on all systems is written to the tape drive.
[Root@linux ~]# Find/-print | Cpio-covb >/dev/st0
# in general, the tape drive using a SCSI interface, the code name is/dev/st0 Oh.
Example two: Check what files are on the tape drive.
[Root@linux ~]# CPIO-ICDVT </dev/st0
[Root@linux ~]# CPIO-ICDVT </dev/st0 >/tmp/content
# in the first action, the files in the tape drive will be listed on the screen, and we can go through the second action,
# Record all the file names to the/tmp/content files.

Example three: Restore the data on the tape back ~
[Root@linux ~]# Cpio-icduv </dev/st0
# in general, the tape drive using a SCSI interface, the code name is/dev/st0 Oh.

Example four: Back up all "files" under/etc to/root/etc.cpio.
[Root@linux ~]# Find/etc-type F | Cpio-o >/root/etc.cpio
# so you can back it up ~ You may also be able to cpio-i </root/etc.cpio
# to catch the data ....


Compression and decompression methods of common compression formats under Linux
Date: 2005-01-20 Source: Linuxbyte Author: Linux Enthusiasts
. tar
Unpacking: Tar xvf Filename.tar
Package: Tar cvf filename.tar DirName
(Note: Tar is packaged, not compressed.) )
. gz
Decompression 1:gunzip filename.gz
Decompression 2:gzip-d filename.gz
Compression: gzip FileName
. tar.gz
Decompression: Tar zxvf FileName.tar.gz
Compression: Tar zcvf FileName.tar.gz DirName
. bz2
Decompression 1:bzip2-d filename.bz2
Decompression 2:BUNZIP2 filename.bz2
Compression: Bzip2-z FileName
. tar.bz2
Decompression: Tar jxvf FileName.tar.bz2
Compression: Tar jcvf FileName.tar.bz2 DirName
. BZ
Decompression 1:bzip2-d
Decompression 2:BUNZIP2
Compression: Unknown
Decompression: Tar jxvf
Compression: Unknown
. Z
Decompression: uncompress filename.z
Compression: Compress FileName
. Tar. Z
Decompression: Tar zxvf filename.tar.z
Compression: Tar zcvf filename.tar.z DirName
. tgz
Decompression: Tar zxvf filename.tgz
Compression: Unknown
. tar.tgz
Decompression: Tar zxvf FileName.tar.tgz
Compression: Tar zcvf FileName.tar.tgz FileName
. zip
Decompression: Unzip
Compression: Zip DirName
. rar
Decompression: rar a Filename.rar
Compression: R ar e filename.rar
RAR please to: download.
After extracting, copy the rar_static to the/usr/bin directory (other directories specified by the $PATH environment variable are also available):
[ROOT@WWW2 tmp]# CP Rar_static/usr/bin/rar
. Lha
Decompression: Lha-e Filename.lha
Compression: Lha-a Filename.lha FileName
LHA please go to:
> After unpacking, copy the LHA to the/usr/bin directory (other directories specified by the $PATH environment variable are also available):
[ROOT@WWW2 tmp]# CP lha/usr/bin/
. rpm
Unpacking: Rpm2cpio filename.rpm | Cpio-div
. Tar. tgz. tar.gz. Tar. Z. tar.bz2. zip. cpio. rpm. Deb. SLP. Arj. rar. Ace. Lha. Lzh
. lzx. Lzs. Arc. SDA. SFX. Lnx. Zoo. cab. kar. cpt. Pit. Sit. Sea
Decompression: sEx x filename.*
Compression: SEx a filename.* FileName
Sex just calls the relevant program, and itself does not have compression, decompression function, please note.
Sex please to: download.
After unpacking, copy the sex to the/usr/bin directory (other directories specified by the $PATH environment variable are also available):
[ROOT@WWW2 tmp]# CP sex/usr/bin/

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: 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.