Linux users often need to back up the data in the computer system, in order to save storage space, often the backup file compression, this article is a summary of the compression and decompression command
. tar.gz
Decompression: Tar zxvf FileName.tar.gz
Compression: Tar zcvf FileName.tar.gz dirName
The Solaris decompression *.tar.gz may be somewhat different and can be decompressed in the following two steps:
1, gzip-d *.tar.gz
2. Tar xvf *.tar
The first step is to extract the *.tar.gz format into the *.tar format first.
The second step, directly unzip the *.tar format file, complete the decompression
---------------------------------------------
. tar
Unpacking: Tar xvf Filename.tar
Tar xvf filename.tar-c DirName (extract to specified folder DirName)
Package: Tar cvf filename.tar DirName
---------------------------------------------
. GZ
Decompression 1:gunzip filename.gz
Decompression 2:gzip-d filename.gz
Compression: gzip FileName
. tar.gz and. tgz
Decompression: Tar zxvf FileName.tar.gz
Compression: Tar zcvf FileName.tar.gz FileName
---------------------------------------------
. 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 FileName
---------------------------------------------
. BZ
Decompression 1:bzip2-d filename.bz
Decompression 2:BUNZIP2 filename.bz
Compression: Unknown
. Tar.bz
Decompression: Tar jxvf FileName.tar.bz
Compression: Tar jcvf FileName.tar.bz FileName
---------------------------------------------
. Z
Decompression: uncompress filename.z
Compression: Compress FileName
. Tar.z
Decompression: Tar zxvf filename.tar.z
Compression: Tar zcvf filename.tar.z DirName
---------------------------------------------
. zip
Decompression: Unzip Filename.zip
Compression: Zip Filename.zip DirName
---------------------------------------------
. rar
Decompression: rar x Filename.rar
Compression: rar a Filename.rar DirName
RAR please to:http://www.rarsoft.com/download.htm Download!
After extracting, copy the rar_static to the/usr/bin directory (other directories specified by the $PATH environment variable are also available):
[email protected] tmp]# CP Rar_static/usr/bin/rar
---------------------------------------------
. Lha
Decompression: Lha-e Filename.lha
Compression: Lha-a Filename.lha FileName
LHA please go to:http://www.infor.kanazawa-it.ac.jp/~ishii/lhaunix/ Download!
> After unpacking, copy the LHA to the/usr/bin directory (other directories specified by the $PATH environment variable are also available):
[email protected] tmp]# CP lha/usr/bin/
---------------------------------------------
. rpm
Unpacking: Rpm2cpio filename.rpm | Cpio-div
---------------------------------------------
. deb
Unpacking: AR p filename.deb data. tar.gz | Tar ZXF-
---------------------------------------------
. Tar. tgz. tar.gz. Tar.z. Tar.bz. 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 call the relevant program, itself and no compression, decompression function, please note!
Sex please to: http://sourceforge.net/projects/sex download!
After unpacking, copy the sex to the/usr/bin directory (other directories specified by the $PATH environment variable are also available):
[email protected] tmp]# CP sex/usr/bin/
Reference Documents: Linux File Compression Tool guide
In fact, to see Help is the best way, the General command can be used "--help" parameter or man command (such as: Mans tar) get common use Method!
---------------------------------------------
Tar command
Tar can create archives for files and directories. With tar, users can create files (backup files) for a specific file, or they can change files in the file or add new files to the file. Tar was originally used to create files on tapes, and users can now create files on any device, such as floppy disks. With the tar command, you can package a whole bunch of files and directories into a single file, which is useful for backing up files or combining several files into one file for easy network transmission. The tar on Linux is the GNU version.
Syntax: tar [main option + Secondary options] file or directory
When using this command, the main option is required, and it tells Tar what to do, auxiliary options are auxiliary and can be used.
Main options:
C Create a new profile. Select this option if the user wants to back up a directory or some files.
R appends the file to be archived to the end of the archive file. This option is available when the user has already made a backup file, and then discovers that a directory or file needs to be appended.
T list the contents of the archive file and see which files have been backed up.
U update file. That is, replace the original backup file with the new file, if the file you want to update is not found in the backup file, append it to the end of the backup file.
X release the file from the archive file.
Accessibility Options:
b This option is set for the tape drive. It is followed by a number that indicates the size of the chunk and the system preset value is (20*512 bytes).
F using a file or device, this option is usually required.
K Save the file that already exists. For example, we restore a file, during the restore process, encountered the same file, will not be overwritten.
m when restoring files, set the modification time of all files to now.
M Create a multi-volume archive file for storage on several disks.
V Detailed report of file information processed by tar. Without this option, TAR does not report file information.
W each step requires confirmation.
Use gzip to compress/unzip the file , plus this option to compress the archive file, but be sure to unzip it using this option when restoring.
Example 1: The Home/home directory including its subdirectories are all backup files, the backup file name is Usr.tar.
$ tar cvf usr.tar/home
Example 2: The home/home directory including its subdirectories are all backup files, and compression, backup file name is usr.tar.gz.
$ tar czvf usr.tar.gz/home
Example 3: Restore and decompress the usr.tar.gz backup file.
$ tar xzvf usr.tar.gz
Example 4: View the contents of the Usr.tar backup file and display it on the display in Split-screen mode.
$ tar TVF Usr.tar | More
To back up a file to a specific device, simply use the device name as the backup file name.
Example 5: The user creates a backup file on the floppy disk of the/DEV/FD0 device and copies all the files in the/home directory to the backup file.
$ tar Cf/dev/fd0/home
To restore files from your device's disk, use the XF option:
$ tar xf/dev/fd0
If a user backs up a file that is larger than the storage space available to the device, such as a floppy disk, you can create a multi-volume tar backup file. The M option instructs the tar command to prompt you to use a new storage device, and when the M option is used to archive a floppy drive, the TAR command reminds you to put a new floppy disk when a floppy disk is full. This allows you to save the tar file to several disks.
$ tar Cmf/dev/fd0/home
To recover files from several disks, simply put the first one in the floppy drive and enter the TAR command with the X and M options. You will be reminded to put another floppy disk if necessary.
$ tar xmf/dev/fd0
---------------------------------------------
gzip command
There are two obvious benefits of reducing file size, one is to reduce storage space, and the other is to reduce transmission time when transferring files over the network. Gzip is a frequently used Linux system command to compress and decompress files, which is both convenient and useful.
Syntax: gzip [option] File name for compression (decompression)
Meaning of each option:
-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:
Size of compressed files (compressed)
Uncompressed file size (uncompressed)
Compression ratio (ratio)
The name of the uncompressed file (uncompressed_name)
-R recursively finds the specified directory and compresses all of its files or is decompressed.
-T test to check that the compressed file is complete.
-V for each compression and decompression file, display the filename and compression ratio.
-num adjusts the speed of compression with the specified number num, -1 (--fast) represents the fastest compression method (low compression ratio), and -9 (--best) represents the slowest compression method (high compression ratio). The system default value is 6.
Suppose a directory/home has a file 123 AAA ABC
Example 1: Compress each file in the/home directory into a. gz file.
$ cd/home
$ gzip *
$ ls
123.gz aaa.gz abc.gz
Example 2: Unzip each compressed file in Example 1, and list detailed information.
$ GZIP-DV *
123.gz: -50.0%--replaced with 123
aaa.gz: -50.0%--Replaced with AAA
abc.gz: -50.0%--Replaced with ABC
$ ls
123 AAA ABC
Example 3: Detailed Example 1 shows the information of each compressed file, and does not understand the pressure.
$ gzip-l *
Compressed uncompressed ratio uncompressed_name
4 -50.0% 123
4 -50.0% AAA
4 -50.0% ABC
About -416.7% (totals)
$ ls
123.gz aaa.gz abc.gz
Example 4: Compress a tar backup file, such as Usr.tar, when the zip file has the extension. tar.gz
$ gzip Usr.tar
$ ls
Usr.tar.gz
---------------------------------------------
Unzip command
How does WinZip compress files under the MS Windows compression software unfold under the Linux system? You can use the Unzip command, which is used to extract a compressed file with a. zip extension.
Syntax: Unzip [options] Compress file name. zip
The meanings of each option are:
-X file list to unzip the file, but not include the specified file file.
-V View the compressed Files directory, but do not press.
The-t test file has no damage, but does not understand the pressure.
The-D directory unlocks the compressed file to the specified directory.
-Z displays only annotations for compressed files.
-N does not overwrite files that already exist.
-O overwrites files that already exist and does not require user confirmation.
-j does not recreate the directory structure of the document, extracting all the files into the same directory.
Example 1: Unzip the compressed file Text.zip in the current directory.
$ unzip Text.zip
Example 2: Extract the compressed file Text.zip in the specified directory/TMP, if the same file exists, ask the unzip command not to overwrite the original file.
$ unzip-n text.zip-d/tmp
Example 3: View the compressed Files directory, but do not understand the pressure.
$ unzip-v Text.zip
---------------------------------------------
Zgrep command
The function of this command is to look for a matching regular expression in a compressed file, using the same as the grep command, except that the object is a compressed file. If the user wants to see if there is a certain word in a compressed file, the Zgrep command is available.