Linux archiving and compression

Archive , also known as packaging , referring to the collection of a file or directory, and this collection is stored in a file. Archive file is not compressed, so it takes up space which is the sum of all files and directories.

Compression is the use of algorithms for processing the file, the file has reached the maximum retention of information, and make the file size smaller purposes. The basic principle is, by looking for repeated bytes within the file, create a same byte dictionary file, and is represented by a code. For example, in a compressed file, there is a more than a "Hello, world," then, in the compressed file, the word will be denoted by a code and write the dictionary file, so that you can achieve reduced file size purpose.

Under Linux, there are two common archive command, tar and dd are (relatively speaking, more extensive use of tar); command have many common compression, such as gzip, zip, bzip2 like. Detailed usage of these commands, the file will do follow-introduced one by one.

tar command to do the packaging operation

When the tar command to package the operation, the basic format of this command is:

[Root @ localhost ~] #tar [options] source file or directory

This command common options and their meanings are shown in Table 1.

Table 1 tar package options and commands common meaning
Options meaning
-c The package multiple files or directories.
-A Append tar files to an archive file.
-f package name Specify the file name of the package. Extension package is used to identify the format of the administrator, so be sure to specify the correct extension;
-v Packed file display process;

Note that when using the tar command can specify options not previously entered options "-." For example, like the use of "cvf" option and the "-cvf" play a role.

tar command to do the de-packaging operations

When the tar command packet is used to make tar solution packaging operation, the basic format of the command is as follows:

[Root @ localhost ~] #tar [Options] archive

When the time for de-packing, the options used as given in Table 2 below.

Table 2 tar solution package options and common meaning
Options meaning
-x Tar package solution to make packaging operations.
-f Specifies the package name you want to extract the tar package.
-t Just see which files or directories have tar package, tar package do not de-packaging operations.
-C directory Packaging Solutions designated location.
-v Display specific process solutions packaged.

packaged as a compressed tar command to do (decompresses pack) Operating

When the tar command while doing packing compression operation, the basic format is as follows:

[Root @ localhost ~] #tar [options] source file or directory archive

Commonly used herein have the following two options, namely:

  • -z: compress and decompress ".tar.gz" format;

  • -j: compression and decompression ".tar.bz2" format.

zip command

Winzip compression program similar to Windows systems, the basic format is as follows:

[Root @ localhost ~] #zip [options] source file compression package name or source directory listing

Note, zip compression package name after the command you need to specify compression, extension clearly written note, in order to decompress use.
The command common options and their meanings are shown in Table 1.

Table 1 zip command options and common meaning
Options meaning
-r Recursive compression directory, and all files and subdirectories in the development of the entire directory compression.
-m After the compressed file, delete the original file, move the file to the equivalent of a compressed file.
-v Display detailed information on the compression process.
-q Not displayed during the execution of the command in compressed time.
- compression level Compression level is a number from 1 to 9, -1 compress faster -9 compress better representatives.
-u Update compressed files that add new files to the archive.

unzip command

unzip command to view and decompress zip file. The basic format of the command is as follows:

[Root @ localhost ~] # unzip [Options] archive name

This command and the respective common options described in Table 1.

Table 1 unzip command options and common meaning
Options meaning
-d directory name Extract the zip file to the specified directory.
-n Do not overwrite existing files when extracting.
-O Overwrite existing files when extracting, and without user confirmation.
-v For more information view the compressed file, including file size of the compressed file contains the file name and compression ratio, but does not do decompression operation.
-t Test compressed file for damage, but not unpacked.
-x file list 解压文件,但不包含文件列表中指定的文件。

gzip命令

gzip 是 Linux 系统中经常用来对文件进行压缩和解压缩的命令,通过此命令压缩得到的新文件,其扩展名通常标记为“.gz”。

再强调一下,gzip 命令只能用来压缩文件,不能压缩目录,即便指定了目录,也只能压缩目录内的所有文件。

gzip 命令的基本格式如下:

[root@localhost ~]# gzip [选项] 源文件

命令中的源文件,当进行压缩操作时,指的是普通文件;当进行解压缩操作时,指的是压缩文件。该命令常用的选项及含义如表 1 所示。

表 1 gzip 命令常用选项及含义
选项 含义
-c 将压缩数据输出到标准输出中,并保留源文件。
-d 对压缩文件进行解压缩。
-r 递归压缩指定目录下以及子目录下的所有文件。
-v 对于每个压缩和解压缩的文件,显示相应的文件名和压缩比。
-l 对每一个压缩文件,显示以下字段:
  • 压缩文件的大小;

  • 未压缩文件的大小;

  • 压缩比;

  • 未压缩文件的名称。

-数字 用于指定压缩等级,-1 压缩等级最低,压缩比最差;-9 压缩比最高。默认压缩比是 -6。

gunzip命令

gunzip 是一个使用广泛的解压缩命令,它用于解压被 gzip 压缩过的文件(扩展名为 .gz)。

对于解压被 gzip 压缩过的文件,还可以使用 gzip 自己,即 gzip -d 压缩包。

gunzip 命令的基本格式为:

[root@localhost ~]# gunzip [选项] 文件

该命令常用的选项及含义如表 1 所示。

表 1 gunzip 命令常用选项及含义
选项 含义
-r 递归处理,解压缩指定目录下以及子目录下的所有文件。
-c 把解压缩后的文件输出到标准输出设备。
-f 强制解压缩文件,不理会文件是否已存在等情况。
-l 列出压缩文件内容。
-v 显示命令执行过程。
-t 测试压缩文件是否正常,但不对其做解压缩操作。

bzip2 命令

bzip2 命令同 gzip 命令类似,只能对文件进行压缩(或解压缩),对于目录只能压缩(或解压缩)该目录及子目录下的所有文件。当执行压缩任务完成后,会生成一个以“.bz2”为后缀的压缩包。
".bz2"格式是 Linux 的另一种压缩格式,从理论上来讲,".bz2"格式的算法更先进、压缩比更好;而 ".gz"格式相对来讲的时间更快。
bzip2 命令的基本格式如下:

[root@localhost ~]# bzip2 [选项] 源文件

源文件指的要压缩或解压缩的文件,该命令常用的选项及各自的含义如表 1 所示。

表 1 bzip2 命令常用选项及含义
选项 含义
-d 执行解压缩,此时该选项后的源文件应为标记有 .bz2 后缀的压缩包文件。
-k bzip2 在压缩或解压缩任务完成后,会删除原始文件,若要保留原始文件,可使用此选项。
-f bzip2 在压缩或解压缩时,若输出文件与现有文件同名,默认不会覆盖现有文件,若使用此选项,则会强制覆盖现有文件。
-t 测试压缩包文件的完整性。
-v 压缩或解压缩文件时,显示详细信息。
-数字 这个参数和 gzip 命令的作用一样,用于指定压缩等级,-1 压缩等级最低,压缩比最差;-9 压缩比最高

注意,gzip 只是不会打包目录,但是如果使用“-r”选项,则可以分别压缩目录下的每个文件;而 bzip2 命令则根本不支持压缩目录,也没有“-r”选项。

bunzip2命令

要解压“.bz2”格式的压缩包文件,除了使用“bzip2 -d 压缩包名”命令外,还可以使用 bunzip2 命令。
bunzip2 命令的使用和 gunzip 命令大致相同,bunzip2 命令只能用于解压文件,即便解压目录,也是解压该目录以及所含子目录下的所有文件。
bunzip2 命令的基本格式为:

[root@localhost ~]# bunzip2 [选项] 源文件

此命令常用的选项以及各自的含义,如表 1 所示。

表 1 bunzip2 命令选项及含义
选项 含义
-k 解压缩后,默认会删除原来的压缩文件。若要保留压缩文件,需使用此参数。
-f 解压缩时,若输出的文件与现有文件同名时,默认不会覆盖现有的文件。若要覆盖,可使用此选项。
-v 显示命令执行过程。
-L 列出压缩文件内容。




Guess you like

Origin blog.51cto.com/14073476/2477288
Recommended