The tar command, "This is just packing, not compression," is the compression. Unpacking: Tar zxvf FileName. TarPackage: Tar czvf FileName. TarDirnamegz Command Decompression1: Gunzip FileName. GZExtract2: gzip-d FileName. GZCompression: gzip FileName. Tar. GZAnd. tgzUnzip: Tar zxvf FileName. Tar. GZCompression: Tar zcvf FileName. Tar. GZDirName compressing multiple files: Tar zcvf FileName. Tar. GZDirName1 DirName2 DirName3 ... bz2 command decompression1: bzip2-d FileName. BZ2 Decompression2: Bunzip2 FileName. BZ2 Compression: BZIP2-ZFileName. Tar. BZ2 decompression: Tar jxvf FileName. Tar. BZ2 compression: Tar jcvf FileName. Tar. BZ2 DIRNAMEBZ Command Decompression1: bzip2-d FileName. BZExtract2: Bunzip2 FileName. BZCompression: Unknown. Tar. BZUnzip: Tar jxvf FileName. Tar. BZZCommand decompression: uncompress FileName. ZCompression: Compress FileName. Tar. ZUnzip: Tar zxvf FileName. Tar. ZCompression: Tar zcvf FileName. Tar. ZDirnamezip Command decompression: Unzip FileName. zipCompression: Zip FileName. zipDirName above this much to see the main is tar others know can oh the following is an example of the time to see the most parameters of tar are described below:-Z: Do you have the properties of gzip at the same time? i.e. do I need gzip compression? -x: Unlock the parameter instructions for a compressed file! -V: Files are displayed during compression! This common-F: Use the file name, please note that after F to immediately answer the file name Oh! Don't add any more arguments! -P: Use the original file's original property (property will not change according to the user)-P: You can use absolute path to compress! -N: Newer than next date (YYYY/MM/DD) will be packaged in the new file! Example: compressing files [[email protected] ~]# TAR-CVF/TMP/ETC.TAR/ETC <== only packaged, not compressed! [[Email protected] ~]# tar-zcvf/tmp/etc.tar.gz/etc <== after packing, compress with gzip[[Email protected] ~]# tar-jcvf/tmp/etc.tar.bz2/etc <== after packing, compress 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. View the contents of a compressed file example two: Check the above/tmp/etc. Tar. GZWhat files are in the 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! Decompression example three: Will/tmp/etc. Tar. GZFile decompression 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/tmp/etc. Tar. GZThe etc/passwd in the inside is untied [[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, than2005/ ./ onNew files are backed up [[email protected] ~]# tar-n ' 2005/06/01 '-ZCVF home.tar.gz/homeExample seven: I want to back up/home, etc, but don't/home/dmtsai[[email protected] ~]# tar--EXCLUDE/HOME/DMTSAI-ZCVF myfile.tar.gz/home/*/etcExample 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! # The point to note is that the output becomes--and the input file becomes--and another | exists ~# This represents the standard output, the standard input and the pipeline command! gzip, zcat command [[email protected] ~]# gzip [-cdt#] File name[[Email protected] ~]# zcat file name. GZParameter:-C: The compressed data is output to the screen, can be processed by data flow redirection;-D: the extracted parameters;-T: can be used to verify the consistency of a compressed file ~ To see if there are errors;#: Compression level, 1 the fastest, but the compression ratio is the worst,-9 the slowest, but the best compression! The preset is -6 ~Example: Example one: Will/etc/man. configCopy to/TMP, and gzip compress [[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 the file of sample one [[email protected] tmp]# gzip-d man.config.gzExample four: The man who untied the example three. configCompress with the best compression ratio and keep the original file [[email protected] tmp]# gzip-9-C man.config > Man.config.gzbzip2, Bzcat command [[email protected] ~]# bzip2 [-cdz] File name[[Email protected] ~]# bzcat file name. bz2Parameter:-C: Output 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: Example one: Put just the/tmp/man. configCompress 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 the file of sample one [[email protected] tmp]# bzip2-d man.config.bz2Example four: The man who untied the example three. configCompress with the best compression ratio and keep the original file [[email protected] tmp]# bzip2-9-C man.config > man.config.bz2Compress command [[email protected] ~]# compress [-DCR] file or directoryParameter:-D: The parameter to decompress-R: can also be compressed together with the files in the directory! -C: Export the compressed data as standard output to screen example: example one:/etc/man. configDuplicate to/tmp and compress [[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--1Root root2605Jul - One: +Mans. config. ZExample two: Unlock just the compression file [[email protected] tmp]# compress-d Man.config.zExample three: the Man. configCompress 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--1Root root4506Jul - One: +Mans. config-rw-r--r--1Root root2605Jul - One: $Mans. 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"Parameter: if: is the input file can also be a device Oh! Of: is the output file Oh ~ can also be a device; BS: Plan a block size, if not set, the preset is +Bytescount: How many BS means. Example: Example one: Backing up/etc/passwd to/TMP/PASSWD. Backamong [[email protected] ~]# dd IF=/ETC/PASSWD of=/tmp/passwd.back3+1Recordsinch3+1Records out[[Email protected] ~]# Ll/etc/passwd/tmp/passwd.back-rw-r--r--1Root root1746The - -: -/etc/passwd-rw-r--r--1Root root1746The in -: $/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: Backup/dev/hda mbr[[email protected] ~]# dd If=/dev/hda of=/tmp/mbr.back bs=512 count=11+0Recordsinch1+0Records 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] <== restoreParameter:-o: Data copy output to a file or device-I: Copy the data from a file or device in the system-T: View the contents of a file or device created by Cpio-C: A newer portable format store-V: Allows the file name to be stored during The screen shows-B: Allows the preset Blocks to be added to5120Bytes, presets are +Bytes! The benefit is that large files can be stored faster (refer to I-nodes's idea)-D: Automatically create a directory! Because the content of cpio may not be in the same directory, then the process of anti-backup will be problematic! This time add-D words, you can automatically set up the required directory! -U: Automatically overwrites newer files with older ones! Example: Example one: All the data on the system is written 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. CpioIn [[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 "3"