Zip is a bit old, but all systems support (.zip ).
Format
Parameter of the file name to be compressed After Zip Compression
Parameters
-1 compression ratio, optional from 1 to 9, 9 is the maximum compression rate.
-C adds comments.
-D decompress a file.
-D does not store the directory information of files.
-F replaces the existing file.
-F: fix the compressed file.
-G: add files to the package.
-M: add the file to the package and delete the source file.
-N does not compress files with specific extensions.
-Q quiet mode.
-R includes subfolders.
-T: Only files after the specified date are compressed.
-T to test whether the compressed file is normal.
-U updates the modified files and new files.
-V displays details.
-X does not compress the specified file.
Unzip is used for decompression. The parameters are similar.
The old archive format (.gz) on gzip linux ).
Format
File name parameter to be compressed after gzip Compression
Parameters
-A or -- ASCII uses the ASCII text mode.
-C or -- stdout or -- to-stdout outputs the compressed file to the standard output device, without changing the original file.
-D or -- decompress Or ---- uncompress To uncompress the compressed file.
-F or -- force forcibly compresses the file. Ignore whether the file name or hard connection exists and whether the file is signed.
-H or -- Help Online Help.
-L or -- list lists information about compressed files.
-L or -- license displays version and copyright information.
-N or -- no-name: the original file name and time stamp are not saved.
-N or -- name: the original file name and time stamp are saved when the file is compressed.
-Q or -- Quiet does not display warning information.
-R or -- Recursive recursive processing: all files and subdirectories under the specified directory are processed together.
-S <compression character string> or ---- suffix <compression character string> to change the compression character string.
-T or -- test to test whether the compressed file is correct.
-V or -- verbose displays the command execution process.
-V or -- version displays version information.
-<Compression efficiency> the compression efficiency is a value ranging from 1 to 9. the preset value is "6". The larger the value, the higher the compression efficiency.
-- Best this parameter has the same effect as the specified "-9" parameter.
-- Fast this parameter has the same effect as the specified "-1" parameter.
Tar is the most common packaging format (.tar)
Format
File name to be compressed after tar-CVF Compression
Parameters:
-C: Create a compressed file
-X
: Unlock a compressed file
-T: View Compressed file Files in
The C/X/t parameter cannot be used at the same time.
-Z: gzip Compression
-J
: Compressed with Bzip2
-V: Details
-F
: Compressed file name. This parameter must be the last parameter.
-P
: Use the original attributes of the original file
-P: absolute paths can be used for compression.
-N
: A New file than the date yyyy/mm/DD will be packaged
-- Exclude file: Do not package the file during compression.
------------- A simple Excerpt from chinaitlab is as follows --------------------
. Tar
Unpack: Tar xvf filename.tar
Package: Tar CVF filename.tar
Dirname
(Note: tar is packed, not compressed !)
---------------------------------------------
. GZ
Decompress 1: gunzip
Filename.gz
Decompress 2: gzip-D filename.gz
Compression: gzip filename
.Tar.gz and
. Tgz
Decompress: Tar zxvf filename.tar.gz
Compression: Tar zcvf filename.tar.gz
Dirname
---------------------------------------------
. Bz2
Extract 1: Bzip2
-D filename.bz2
Decompress 2: bunzip2 filename.bz2
Compression: Bzip2-z
Filename
.Tar.bz2
Decompress: Tar jxvf filename.tar.bz2
Compression: Tar jcvf
Filename.tar.bz2
Dirname
---------------------------------------------
. Bz
Extract 1: Bzip2
-D filename. bz
Decompress 2: bunzip2 filename. bz
Compression: Unknown
. Tar. bz
Decompress: Tar
Jxvf
Filename.tar. bz
Compression: Unknown
---------------------------------------------
. Z
Decompress: uncompress
Filename. Z
Compression: compress filename
. Tar. Z
Decompress: Tar zxvf
Filename.tar. Z
Compression: Tar zcvf filename.tar. Z
Dirname
---------------------------------------------
. Zip
Decompress: unzip
Filename.zip
Compression: Zip filename.zip
Dirname
---------------------------------------------
. Rar
Decompress: RAR
A filename.rar
Compression: R ar e
Filename.rar
RAR Please download to: http://www.rarsoft.com/download.htm!
After decompression, copy rar_static to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
[Root @ www2
TMP] # cp rar_static
/Usr/bin/RAR
---------------------------------------------
. LHA
Decompress: LHA
-E filename. LHA
Compression: LHA-a filename. LHA
Filename
Lha please: http://www.infor.kanazawa-it.ac.jp /~ Ishii/lhaunix/download!
> After decompression, copy LHA to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):
[Root @ www2
TMP] # cp LHA
/Usr/bin/
---------------------------------------------
. Rpm
Unpack: rpm2cpio
Filename. RPM | cpio
-Div
---------------------------------------------
. Deb
Unpack: Ar P
Filename. Deb data.tar.gz | tar zxf
-
---------------------------------------------
----------------------- Use details of the converted tar -------------------------------------------
Tar is "Tape
Archive, short for tape archiving, appeared early in a computer that has no floppy drive, hard drive, or disc drive. At that time, the release and backup of software required large volumes of tape, the first few running on the computerProgramThere must be a tape reading program. Over time,
The tar command gradually becomes a tool for archiving many files. Currently, many programs for Linux operating systems are packaged as tar files.
The format of the tar command is:
Tar [Option] <File>;
The tar command has many parameters. The F option, device, or file name can be used to indicate that the tar command places the file in a specific device or file. When a file is created for a tar file, the extension of the file name is usually if a directory name is specified, all its subdirectories will be included in the file.
The format of the tar command and the F option is as follows:
# Tar opionsf archive-name.tar directory-and-filenames
To create an archive, use the C option, which, together with the F option, creates the archive in the device or file. Enter this option on the left of the F option. In the following example, all directories of mydirand Taobao are stored in myarch.tar.
# Tar CF myarch.tar mydir
If you want to change the files in the archived directory, you can use the U option to make tar update files in the file. Tar compares the last modification time of each file and the file in the corresponding user directory, and then
Copy the modified file after the last archive to the archive file. Files created in the user directory will also be added to the file. In the following example
Modify or modify the file to update the myarch.tar file.
# Tar UF myarch.tar mydir
To view which files are stored in an archive, run the tar command and the T option. The following command lists all files stored in the myarch.tar file:
# Tar TF myarch.tar
To back up a file to a specific device, you only need to use the device name as the file. In the following example, you create an archive in the/dev/fdo disk and copy all the files in the mydir directory to the archive.
# Tar CF/dev/fdo mydir
To restore files on a device disk, use the xf option:
# Tar xf/dev/fdo
If the size of the backup file exceeds the memory available for the device, such as a floppy disk, you can create a tar file with Multiple labels. When you use the M option to archive data to a floppy disk, the tar command will remind you to put a new floppy disk when a floppy disk is full.
# Tar CMF/dev/fdo mydir
To restore the files on several disks, you only need to put the first floppy disk into the soft drive, and then enter the tar command with the X and m options. If necessary, you will be reminded to put it on another floppy disk.
# Tar xmf/dev/fdo
The tar operation does not compress files. If you want to compress an archive file, you can instruct tar to activate the gzip utility to compress the file before archiving. With the Z option, tar uses gzip to compress the file before archiving the file. When the file is restored, the same Z option will activate gzip to decompress the file.
# Tar CZF myarch.tar mydir
It is worth noting that a single file in the compressed file is different from the whole compressed file. Usually, file files are combined into a tar file to facilitate transmission. In order to shorten the transmission time, the file should
The smaller the size, the better. You can compress it and then transfer the compressed version. The recipient can decompress the package and restore the tar file. Using gzipon A tarfile will have a .tar.gz extension.
. The extension name .gz is added to the compressed GZIP file name.
The example below creates a compressed example of myarch.tarwith the extension of .gz.
# Gzip myarch.tar
# Ls
Using myarch.tar.gz
The tar command has many parameters, but it is not difficult to use. It can quickly and simply generate archive files for any required sub-directories.
First, create a subdirectory with three files, and then create a subdirectory with the other three files, as shown below:
# Mkdir mydir
# Cd mydir
# Touch file1 file2 file3
#
Mkdir mydir2
# Cd mydir2
# Touch file21 file22 file23
# Cd ../..
# Tree mydir
Mydir
File1
File2
File3
Mydir2
File21
File22
File23
Now you have a sub-directory and a file in it. Use the C (generated) and F (File) parameters of this command to generate a tar file:
# Tar CF mydir.tar mydir
# Ls-L *. Tar
-R w-r --
1 bball u s e r s 10240 Jan 5 15: 01 mydir. T A R
Note that the original subdirectories have not changed. By default, the tar command does not delete the original subdirectories and files. If you want to see the command execution process, you can use the V parameter as follows:
# Tar CVF mydir.tar mydir
Mydir/
Mydir/file1
Mydir/file2
Mydir/file3
Mydir/mydir2/
Mydir/mydir2/file21
Mydir/mydir2/file22
Mydir/mydir2/file23
The tar command displays the subdirectories and file names that are being added to the file. Use the W parameter, that is, the interaction parameter, so that the tar command will ask if you want to add each file during execution. When you want to selectively back up subdirectories with few contents, this is very convenient, as shown below:
# Tar CWF mydir.tar mydir
Add mydir? Y
Add
Mydir/file1? N
Add mydir/file2? Y
Add mydir/file3? N
Add
Mydir/mydir2? Y
Add mydir/mydir2/file21? Y
Add
Mydir/mydir2/file22? N
Add mydir/mydir2/file23? Y
In the preceding example, the files file1, file3, and file22 are not archived. You can use the t parameter of the tar command to list the content in the file. The F parameter defines the tar file used for the operation, as shown below:
# Tar TF mydir.tar
Mydir/
Mydir/file2
Mydir/mydir2/
Mydir/mydir2/file21
Mydir/mydir2/file23
Note that if the order of parameters is incorrect, the tar command displays the error message and exits.
Next let's take a look at how to release the entire file or one of the files. If you want to release all the files, you can use the-x release parameter and-f. To understand the command execution process, you can also add the-V parameter:
# Tar xvf mydir.tar
Mydir/
Mydir/file2
Mydir/mydir2/
Mydir/mydir2/file21
Mydir/mydir2/file23
If you only want to release several files from the file, you can use the W parameter again:
# Tar xvwf mydir.tar
Extract mydir /? Y
Mydir
Extract
Mydir/file2? Y
Mydir/file2
Extract mydir/mydir2 /? Y
Mydir/mydir2/
Extract mydir/mydir2/file21? Y
Mydir/mydir2/file21
Extract mydir/mydir2/file23? Y
Mydir/mydir2/file23
The preceding example shows that the file is viewed and the file is released interactively. If you only want to release a file from the file, you can specify the file in the command line. As an example, I first deleted the original mydir sub-directory and then used an empty sub-directory to perform the following operations:
# Tar xf mydir.tar mydir/mydir2/file23
# Tree mydir
M y d I
R
--Mydir2
--File23
1 directory, 1 file
Note: As you can see, only one file is released. Although the tar command does not overwrite the entire subdirectory, it will overwrite the files with the same file name.
It is worth mentioning that other programs, such as BRU-2000 or taper script programs, can also be used to back up the system or selected files and subdirectories. The OpenLinux operating system can also use cron schedules to automatically archive files.
Create a cpio File
Cpio commands can import or copy files from tar or cpio files. Because the cpio command is compatible with the tar command, I will not detail how it works here. However, this command has some functions not available for tar commands, as shown below:
◆ Supports cpio and tar file formats;
◆ Supports many old-fashioned tape data formats;
◆ File names that can be read through an MTS queue.
Only a few Linux software packages are released in cpio format. If you are interested in the details of the cpio command, read its user manual.
Use gzip to compress files
The gzip command is used to compress files. It can be used not only to compress large and rarely used files to save disk space, but also to form popular compressed file formats in the Linux operating system together with the tar command. According to statistics, the gzip command has 60% ~ 70% compression rate.
The format of the gzip command is:
Gzip [Option]
Gzip is easy to use. To compress a file or tape file, enter the following content:
# Gzip mydir.tar
In the initial state, gzips will compress the file and add a .gz extension, and then delete the original file. To decompress the file, use the corresponding program command gunzip or
-D decompression parameter of the gzip command. However, the extension ensures that the uncompressed file has the extension .gz (or. Z,-GZ,. Z,-Z, or _ z). Otherwise, the gzip command and
The gunzip command displays error information. If you want to use your own extension, you can use the-s extension parameter, as shown below:
# Gzip-S. gzipped mydir.tar
Gzip can also process file packages compressed by zip, compress, and pack commands. If you want to see more information during compression or decompression, you can use the-l column list.
The parameter shows the file length when the file is compressed or decompressed. In the previous example, after compressing the subdirectory mydir, you can use the gzip command to obtain the relevant data as follows:
# Gzip-l mydir.tar.gz
Compressed uncompr. Ratio
Uncompressed_name
312 21330 98.2% mydir.tar
In addition, Gzip also has a very useful parameter-T, which can be used to test the integrity of the compressed file. If the file is normal, Gzip will not display it. If you want to see the OK letters, you can use the-TV parameter when testing a file.
Compress files
The compress command is used to compress files just like the file name. This is a very early compression program in UNIX, which is reduced by using adaptive lemple-Ziv encoding.
The size of the file. Each file is replaced by a compressed file with the. Z extension, but the file owner relationship, access time, and modification time remain unchanged. Accept the standard if no guidance file is provided
The input file is compressed and delivered to the standard output.
The format of the compress command is:
Compress [Option]
There is an uncompress command corresponding to compress. Its format is as follows:
Uncompress [Option]
It restores the compressed file ". Z.
The options for the compress and uncompress commands are as follows:
◆-C is written to the standard output without changing the file.
◆-F is forcibly compressed, even if the file is not actually reduced or the. Z file already exists, it is compressed.
◆-V shows the percentage of each compressed file.
The following example describes how to use the compress command:
# Compress File
AboveCodeIt indicates that the generated compressed file. Z is replaced by file, and the input must be decompressed:
# Uncompress file. Z
Note: like using the gzip command, you must provide a file name with the. Z extension when using the uncompress command. Otherwise, the uncompress command displays an error message.