The Linux compression/decompression command uses the method compress command [[[email protected] ~]# compress [-DCR] file or directory parameter:-D: The parameter to decompress-R: can also be given simultaneously with the file in the directory [ This parameter is used with caution when comparing dangerous]-c: Exporting compressed data as standard output to screen example: example one: Copy/etc/install.log to/tmp and compress [[email protected] ~]# cd/t Mp[[email protected] tmp]# cp/etc/install.log[[email protected] tmp]# compress install.log[[email Protected] tmp]# ls-l-rw-r--r--1 root root 2605 Jul 11:43 install.log.z Example Two: Unpack just the compressed file [[email protected] tmp]# Co mpress-d install.log.z or uncompress install.log.z example three: Compress Install.log into another file to back up [[email protected] tmp]# Compress -C install.log > install.log.back.z[[email protected] tmp]# ll install.log*-rw-r--r--1 root root 4506 Jul 27 11:4 3 install.log-rw-r--r--1 root root 2605 Jul 11:46 install.log.back.z# The parameter of-C is interesting, and he will output the data of 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. Example four: Compressing each file under the TMP directory [[email protected] tmp]# compress-r/tmp/This command compresses the TMP directory and every file in the subordinate directory. Z file, for this command with-R is used sparingly during normal testing, I will have a cup with the whole/etc eyeThe system has been completely compressed, causing problems. Note: Compress is the simplest compression command and is rarely used at present because the back basic has also been replaced by gzip compression commands, compress's compressed files can be manipulated by gzip,zcat commands. gzip, Zcat command [[email protected] ~]# gzip [-cdt#] File name [[email protected] ~]# zcat file name. GZ parameter:-C: Outputs the compressed data to the screen, Can be handled by data flow redirection;-D: decompressed parameters,-T: can be used to verify the consistency of a compressed file, to see if there are errors in the file,-#: compression level, 1 the fastest, but the worst compression ratio, 9 slowest, but the best compression, the default is-6. Example: Example one: Copy the Install.log to/tmp and compress the [[email protected] tmp]# CP ~/install.log with gzip. [[email protected] tmp]# gzip install.log# at this point Install.log will become install.log.gz example two: Read the file contents of example one [[email Protected] tmp]# Zcat install.log.gz# The contents of the file after the install.log.gz decompression are shown in this screen example three: Extracting a file from sample one [[email protected] tmp]# gzip-d install.log.gz or Gunzip install.log.gz# at this time install.log.gz will become Install.log example four: the example of three untied Install.log with best compression ratio and retains original file [[email protected] tmp]# gzip-9-C install.log > INSTALL.LOG.GZ Note: Since gzip is mainly used instead of compress, the Compress compressed file can also be decompressed with gzip. Zcat is also a compressed file that can read both compress and gzip. bzip2, Bzcat command [[email protected] ~]# bzip2 [-cdz] File name [[email protected] ~]# bZcat file name. bz2 parameter:-C: Output data generated by the compression process to the screen-D: uncompressed parameter-Z: Compressed parameter-#: Same as gzip, all in the calculation of compression ratio parameters, 9 best, 1 fastest. Example: Example one: Compress just the/tmp/install.log with bzip2 [[email protected] tmp]# bzip2-z install.log# at this time Install.log will become Install.log . bz2! Example two: Read the file contents of sample one [[email protected] tmp]# bzcat install.log.bz2# This screen will show install.log.bz2 Example of file content after decompression: Unzip the file of example one [[email protected] tmp]# bzip2-d install.log.bz2 or Bunzip install.log.bz2 example four: untie The example three Install.log compressed with best compression ratio and retains original file [[email protected] tmp]# bzip2-9-C install.log > INSTALL.LOG.BZ2 Note: If you find that the file name is called. BZ,BZ2,TBZ,TBZ2 when you extract the files, you can try the decompression operation with BZIP2, or you can try to read the contents of the compressed file with Bzcat; for bzip2, Gzip This two command has been tested to find that the bzip2 compression ratio is better than gzip. Tar command [[[email protected] ~]# tar [-cxtzjvfppn] file or directory .... Parameter:-C: Create a parameter directive for a compressed file (the meaning of Create);-X: Unlocks a compressed file's parameter directive-T: View the files inside the Tarfile special attention, in the parameter release, c/x/t only can 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? That is, if you need to use BZIP2 compression-V: Compression of the process to display each packed compressed file this common, but not recommended in the background execution process-F: Use the file name, please note that after F to immediately answer the file name do not add parameters such as using the [TAR-ZCVFP tfileSfile] is the wrong way of writing, to write [TAR-ZCVPF Tfile sfile] only to-P: Using the original file properties (the package file attributes will not change according to the user)-P (uppercase): You can use the absolute path to compress [ This parameter as far as possible not to use can be said to be a more dangerous parameter, if you add this parameter packaging compression after someone else to get the compressed file to extract, it happens that he in this absolute path also have these files then unzip his original file will be overwritten]-n: than the date after the next (YYYY/MM/DD) and new ones will be packaged into the new file (tar-cvf/tmp/etc.tar/etc-n 20110321)--exclude file: Do not package file in the process of compression! Example one: package all files in/etc directory into/tmp/etc.tar[[email protected] ~]# tar-cvf/tmp/etc.tar/etc <== package only, do not compress [[email& Nbsp;protected] tmp]# tar-czvf/tmp/etc.tar.gz/etc <== after packaging, with gzip compression [[email protected] tmp]# tar-cjvf/tmp/etc.t Ar.bz2/etc <== after packaging, in order to bzip2 compression # Special attention, after the parameter F is the name of their own, we are accustomed to use. Tar as the identification, if the z parameter, then the. tar.gz or. tgz to represent gzip compressed tar F Ile, if the addition of the J parameter, the. tar.bz2 as the file name, in fact, the file name suffix itself is no practical meaning just for the convenience of remembering the file is what the command compression. # When the above instruction is executed, a warning message is displayed: # "tar:removing leading '/' from member names" that is a special setting for absolute paths. Example two: Check the files in the/tmp/etc.tar.gz file [[email protected] tmp]# TAR-ZTVF etc.tar.gz because we use gzip compression, so to view the files in the tar file, It's important to add Z to this parameter [[email protected] tmp]# TAR-JTVF etc.tar.bz2 because we use bzip2 compression, so to see the files in the tar file, you have to add the J parameter example three: Extract the/tmp/etc.tar.gz file under/usr/local/src [Email prot Ected] src]# cd/usr/local/src/[[email protected] src]# tar-xzvf/tmp/etc.tar.gz or tar-xzvf/tmp/etc.tar.gz < u sr/local/src/# in the case of a preset, we can unzip the file anywhere! In this example, I first change the working directory to/USR/LOCAL/SRC, and untie/tmp/etc.tar.gz, then the unpacked directory will be in/USR/LOCAL/SRC/ETC. In addition, if you enter/usr/local/src/etc you will find that the file attributes in this directory may differ from/etc/. Example four: under/tmp, I just want to untie the etc/passwd inside the/tmp/etc.tar.gz [[email protected] etc]# tar-zxvf/tmp/etc.targ etc/passwd# I can Through the TAR-ZTVF to check the name of the file within the Tarfile, if only a single file, it can be issued in this way, note that the root directory in the etc.tar.gz/is taken away! Example five: Back up all files within the/etc/and save their permissions [[email protected]/]# tar-zxvpf/tmp/etc.tar.gz/etc# The properties of this-p are important, Especially when you want to keep the properties of the original file in example six: In/home, newer than 2005/06/01 files are backed up [[email protected]/]# tar-n ' 2005/06/01 '-ZCVF Home.tar.gz/hom E example seven: I want to back up home///etc, but don't/home/oracle[[email protected]/]# tar--exclude/home/oracle-zcvf myfile.tar.gz/home/* /etc Example eight: Will/etc/hitThe package is immediately unlocked at/TMP without generating the file [[[email protected] asm01~]# cd/tmp[[email protected] ASM01 tmp]# TAR-CVF-etc | TAR-XVF-# This action is a bit like Cp-r/etc/tmp still has its purpose # Note that the output file name becomes-and the input file name becomes-and another | Present, which represents the standard output, the standard input, and the pipeline command, respectively. Zipzip is a widely used compression program, the file is compressed after it will produce a ". zip" extension of the compressed file, in the compression, no need to pack, packaging and then compression, compression efficiency is lower, the default is 9, that is, the maximum efficiency. Zip [-options] destination file source file parameter:-d deletes the specified file from within the compressed file. -F The effect of this parameter is similar to specifying the "-u" parameter, but not only updates the existing file, and if some files do not already exist in the compressed file, use this parameter to add it to the compressed file. -F attempt to repair a corrupted compressed file. -G compresses the file after it is appended to the existing compressed file, rather than creating a new compressed file. -I template style > compress only files that match the criteria. -j saves only the file name and its contents, not any directory names. -J Delete unnecessary data before compressing the file. -L displays copyright information. -M compress the file and add the compressed file, delete the original file, that is, move the file to the compressed file-n Tail string > Do not compress the file with a specific tail string. -O to compress files that have the most recent change time in the file, set the change time for the compressed file to be the same as the file. -Q does not list the file names that are compressed during instruction execution. -R recursive processing, all files and subdirectories under the specified directory are processed together with the-T date time > Set the date of the compressed file to the specified date. -T checks that each file within the backup file is correct. -U replace the newer file into the compressed file. -V Displays the instruction execution process or displays version information. -X Template style > exclude eligible files when compressing. -X does not save additional file attributes. -Z adds a comment to the compressed file. -$ Save the volume book name of the disk where the first compressed file is located. -# compression efficiency is a value between 1-9. The greater the number, the higher the compression efficiency (default is 9) Example 1: Compress the database directory into the/usr directory [[email protected] ~]# ZIp-rq/usr/database.zip Database Example 2: Checking the accuracy of compressed files [[email protected] usr]# zip-t Database.zip Example 3: Extract all files from the install directory and subdirectories without preserving the original directory [[email protected] images]# zip-rqj/usr/test Installunzipunzip the unzip program for the. zip archive. Syntax: Unzip [-cflptuvz][-agcjlmnoqsvx][-p password >][.zip file] [file][-d directory >][-x file] or unzip [-z] Parameter:-C Displays the extracted results to the screen, and the characters Make the appropriate conversions. -F Updates an existing file. -L Displays the files contained within the compressed file. -P, similar to the-c parameter, displays the results of the decompression to the screen, but does not perform any conversions. -T checks that the compressed file is correct. -U is similar to the-f parameter, but in addition to updating existing files, other files in the compressed file are extracted to the directory. -V displays detailed information when executed. -Z Displays only the memo text of the compressed file. -A necessary character conversion for the text file. -B Do not convert the text file to character. The file names in the-C compressed file are case sensitive. -J does not handle directory paths that are contained in compressed files. -L Changes all the file names in the compressed file to lowercase. -M sends the output to the more program processing. -N Do not overwrite the original file when extracting. -O do not need to ask the user first, unzip overwrite the original file after execution. (the default is to ask the user)-Q executes without displaying any information. -S converts white space characters in the file name to baseline characters. -X Unzip while the original uid/gid of the file is stored back. [file] Specifies which files in the. zip archive to process. -D directory > Specifies the directory to be stored after the file has been decompressed. -X File > Specifies which files in the. zip archive are not processed. -Z unzip-z equals execute zipinfo instruction. For example, extract the compressed files to the current directory unzip Files.zip if you want to extract the compressed files into the Hat directory under the current home directory: unzip-d ~/hat FILES.ZIPDD command DD can read the contents of the device, The entire device can then be backed up into a single file, which is used in many of the more important parameters described below. [[EMAIL&NBSp;protected] ~]# dd if= "input_file" of= "Outptu_file" bs= "block_size" \ count= "number" parameter: if: is the input file, It can also be device of: output file, or device BS: Plan the size of a block, if not set, the preset is 512 bytes count: How many BS means. Example: Example one: Backing up/etc/passwd to/tmp/passwd.back [[email protected]~] #dd if=/etc/passwd of=/tmp/passwd.back5+1 Records In5+1 Records out[[email protected] ~]# ll/etc/passwd/tmp/passwd.back-rw-r--r--1 root root 2765 Mar 13:17/etc/ passwd-rw-r--r--1 root root 2765 Mar 13:51/tmp/passwd.back# take a closer look, my/etc/passwd file size is 2756 bytes because I didn't set BS, so the Presets are The bytes is a unit, so the above 5+1 indicates that there are 5 complete bytes, and the meaning of another block under the bytes, in fact, it feels like the CP command. Example two: Backup/DEV/SDA mbr[[email protected]~]# dd IF=/DEV/SDA of=/tmp/mbr.back bs=512 count=1;1+0 records in1+0 Records o ut# this has to be well understood, we know that each hard disk MBR for bytes, is placed on the hard disk of the first sector, so I can use this way to the MBR of all the data are recorded, really very powerful! Example three: Back up the entire/DEV/SDA1 partition [[email protected]~]# DD if=/dev/sda1 of=/tmp/filename bs=1024# This command is very powerful, the whole Full backup of partition contentGet down. The latter must not be in the/DEV/SDA1 directory ah otherwise, how to read can not finish. This action is very useful, if another day you have to complete the entire partition content to fill back, you can use the DD if=/some/file of=/dev/sda1 to write data to the hard disk. If you want the entire hard disk backup, like Norton's Ghost software in general, from disk to disk, the use of DD can be completed. However, DD says you can back up the entire partition or disk, but if you want to write data back to the file system, you might need the original file system to succeed. Cpio command [[email protected] ~]# cpio-covb > [file|device] <== backup [[email protected] ~]# Cpio-icduv < [fil E|device] <== restore parameter:-o: Copy data to a file or device-I: Copy data from a file or device to the system-T: View the contents of a file or device created by Cpio-C: A newer, removable-value format Storage-V: Let the file name in the stored procedure -m:preserve-modification-time can be displayed on the screen when you create a file, the previous file modification time is retained-B: The preset Blocks can be increased to 5120 bytes, the preset is bytes, The advantage is that large files can be stored faster (please refer to the concept of i-nodes)-D: Automatically set up the directory, because the content of cpio may not be in the same directory, so there is a problem in the restore process, this time with the-D word, you can automatically set up the required directory-U : Automatically overwrites newer files with older file Examples: Example one: All data on all systems is written to the tape drive [[email protected] ~]# Find/-print | Cpio-covb >/dev/st0# in general, a tape drive using a SCSI interface, codenamed/dev/st0 Example II: Check what's on the tape drive [[email protected] ~]# CPIO-ICDVT </d Ev/st0[[email protected] ~]# CPIO-ICDVT </dev/st0 >/tmp/content# in the first action, the files on the tape drive will be listed on the screen, and we can record all the filenames to the/tmp/content file through the second action: Restore the data on the tape back [[email protected] ~]# Cpio-icduv </dev/st0# in general, a tape drive using a SCSI interface, codenamed/DEV/ST0, example four: Back up all [text] items under/etc to/root/etc.cpio [email protect Ed] ~]# Find/etc-type F | Cpio-o >/root/etc.cpio# So you can back up or CPIO-IVDM </root/etc.cpio to get the files out. Note: Cpio feeling is not very useful, but it is a good tool to backup, sleepy as it can back up any files, including/dev in any device files, so it is very important.
How to use the Linux compression/decompression command