Linux compression (decompression) command

Source: Internet
Author: User
Tags gz file

Linux Packaging compression command Rollup Linux Packaging Compression Command summary






Tar command
[[Email protected] ~]# tar [-cxtzjvfppn] files and directories ....
Parameters:
-C: Create a compressed file parameter directive (the meaning of Create);
-x: Unlock the parameter instructions for a compressed file!
-T: View the files inside the Tarfile!
In particular, in the release of the parameters, c/x/t can only exist one! Cannot exist at the same time!
Because it is not possible to compress and decompress simultaneously.
-Z: Do you have the properties of gzip at the same time? i.e. do I need gzip compression?
-j: Do you have bzip2 properties at the same time? i.e. is it necessary to compress with bzip2?
-V: Files are 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! Don't add any more arguments!
For example, using "TAR-ZCVFP tfile sfile" is the wrong way to write
"TAR-ZCVPF tfile sfile" Just right!
-P: Use original file properties (attributes are not changed according to user)
-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: Package all the files in the/etc directory into/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 <== packaged, compressed with gzip
[[email protected] ~]# tar-jcvf/tmp/etc.tar.bz2/etc <== packaged, bzip2 compressed
# 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 what files are in the above/tmp/etc.tar.gz file?
[Email protected] ~]# 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 important!

Example three: Extracting the/tmp/etc.tar.gz file under/USR/LOCAL/SRC
[Email protected] ~]# CD/USR/LOCAL/SRC
[Email protected] 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.
[Email protected] ~]# cd/tmp
[Email protected] 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,
# can be released in this way! Notice that! The root directory within the etc.tar.gz/is taken away!

Example five: Back up all the files in the/etc/and save their permissions!
[Email protected] ~]# tar-zxvpf/tmp/etc.tar.gz/etc
# The properties of this-p are important, especially if you want to keep the properties of the original file!

Example six: In/home, more than 2005/06/01 new files are 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: Unpack the/etc/directly under/TMP without generating files!
[Email protected] ~]# cd/tmp
[Email protected] 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!
# This part we'll be talking about this command again in Bash Shell and explain it to everyone!




gzip, Zcat command
[[Email protected] ~]# gzip [-cdt#] File name
[[email protected] ~]# zcat file name. gz
Parameters:
-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, 9 slowest, but the best compression! The preset is-6 ~
Example:
Example one:/etc/man.config is copied to/TMP and compressed with gzip
[Email protected] ~]# cd/tmp
[Email protected] tmp]# cp/etc/man.config.
[Email protected] tmp]# gzip Man.config
# at this time Man.config will become man.config.gz!
Example two: Read the file contents of sample one!
[Email protected] tmp]# Zcat man.config.gz
# At this point the screen will show the contents of the file after the man.config.gz decompression!!

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

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


bzip2, Bzcat command
[[email protected] ~]# bzip2 [-cdz] File name
[[email protected] ~]# bzcat file name. bz2
Parameters:
-C: Output 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:
Example one: Compress just the/tmp/man.config with bzip2
[Email protected] tmp]# bzip2-z man.config
# at this time Man.config will become man.config.bz2!
Example two: Read the file contents of sample one!
[Email protected] tmp]# Bzcat man.config.bz2
# At this point the screen will show the contents of the file after the MAN.CONFIG.BZ2 decompression!!

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

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


Compress command
[[email protected] ~]# compress [-DCR] file or directory
Parameters:
-D: Parameters to decompress
-R: can also be compressed together with the files in the directory!
-C: Output compressed data to standard output (outputs to screen)
Example:
Example one:/etc/man.config is copied to/TMP and compressed
[Email protected] ~]# cd/tmp
[Email protected] tmp]# cp/etc/man.config.
[Email protected] tmp]# compress man.config
[Email protected] 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
[Email protected] tmp]# compress-d man.config.z

Example three: compressing the man.config into another file to back up
[Email protected] tmp]# compress-c man.config > Man.config.back.z
[email protected] 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
[[email protected] ~]# dd if= "input_file" of= "Outptu_file" bs= "Block_size" \
count= "Number"
Parameters:
If: The input file is also 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:
Example one: Backup/etc/passwd to/tmp/passwd.back
[email protected] ~]# DD if=/etc/passwd of=/tmp/passwd.back
3+1 Records in
3+1 Records out
[Email protected] ~]# 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 not full of bytes!
# In fact, it feels like the CP command ~

Example two: Backing up the/dev/hda MBR
[[email protected] ~]# 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 powerful! ^_^

Example three: Back up the entire/DEV/HDA1 partition.
[email protected] ~]# DD if=/dev/hda1 OF=/SOME/PATH/FILENAEM
# This command is very powerful! 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 be ~ very bad!



Cpio command
[[email protected] ~]# CPIO-COVB > [file|device] <== Backup
[[email protected] ~]# Cpio-icduv < [file|device] <== Restore
Parameters:
-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: Let the preset Blocks be added to 5120 bytes, the preset is 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:
Example one: Write all the data on the system to the tape drive!
[[email protected] ~]# Find/-print | Cpio-covb >/dev/st0
# in general, use a SCSI interface tape drive, code is/DEV/ST0 Oh!
Example two: Check what files are on the tape drive?
[Email protected] ~]# CPIO-ICDVT </dev/st0
[Email protected] ~]# 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 ~
[Email protected] ~]# Cpio-icduv </dev/st0
# in general, use a SCSI interface tape drive, code is/DEV/ST0 Oh!

Example four: Back up all "files" under/etc to/root/etc.cpio!
[Email protected] ~]# 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!!!!

Linux compression (decompression) command

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: info-contact@alibabacloud.com 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.