Linux中命令行上的ZIP文件

ZIP文件 (ZIP files)

The most popular archiving utility in the Microsoft world is the ZIP file. It is not as established in Linux but is well sustained by the zip and unzip commands.

在Microsoft世界中,最流行的归档实用程序是ZIP文件 。 它不是Linux中建立的,但是可以通过zip和unzip命令很好地维持。

Like we have discussed earlier, we can use TAR or Gzip/bzip2 for compression or decompression, another popular alternative is ZIP.

就像我们之前讨论的那样,我们可以使用TARGzip / bzip2进行压缩或解压缩,另一种流行的替代方法是ZIP

示例1:压缩 (Example 1: Zipping)

Let's try with archiving some files and compressing them.

让我们尝试将一些文件存档并压缩它们。

Zip in Linux

Let's break the code...

让我们打破代码...

We have syntax of ZIP is:

我们的ZIP语法是:

    zip ZIP_name  Filename1 filename2 ...

So the first argument is ZIP_name that is the name of ZIP we wanted to be followed by list of files, in our case, we used wild-character (*) for the list of files. Zip provides a verbose output the files and the compression ratio, unlike in Tar or gzip.

因此,第一个参数是ZIP_name ,它是我们要在其后跟随文件列表的ZIP名称,在本例中,我们使用通配符(*)作为文件列表。 Zip提供详细的文件输出和压缩率,与Tar或gzip不同

Zip will not recurse into any subdirectories by default so we need to use –r option explicitly.

默认情况下, Zip不会递归到任何子目录中,因此我们需要显式使用–r选项。

例子2 (Example 2)

In the above example (1), we can't recurse into subdirectories by default like we saw in case if tar but with option r we can:

在上面的示例(1)中,默认情况下我们无法递归到子目录,就像在tar情况下看到的那样,但是使用选项r可以:

Zip in Linux 2

In the above example, in our folder (or directory) name 'File' contain 10 .jpg files and 1 zip file and now this will let zip command to recurse through subdirectories.

在上面的示例中,在我们的文件夹(或目录)中,名称“文件”包含10个.jpg文件和1个zip文件,现在这将使zip命令通过子目录递归。

In the aboveexample (2), all files under 'File' directory added because of the –r option we used.

在上面的示例(2)中,由于使用了–r选项,因此添加了'File'目录下的所有文件。

We can list files in the zip or unzip command by using –l option (list):

我们可以使用–l选项(列表)以zip或unzip命令列出文件:

示例3:解压缩 (Example 3: Unzipping)

For extracting files from the zip, we use unzip command, it is same as creating an archive.

为了从zip中提取文件,我们使用unzip命令 ,这与创建存档相同。

Syntax:

句法:

    unzip ZipName.zip

As in Example 1, we will have the same option except this time files will extract. Let's unzip the file with –l option:

与示例1一样,除了这次将提取文件之外,我们将具有相同的选项。 让我们使用–l选项解压缩文件:

Zip in Linux 3

In the above image, we can see that we used –l option for listing, which produces size date of creation and name of the file on output.

在上图中,我们可以看到我们使用了-l选项进行列表,该选项生成了创建的大小日期和输出文件的名称。

Note: In case, we want to extract specific files we can use the following format:

注意:如果要提取特定文件,可以使用以下格式:

    unzip ZIPname.zip filename

With the above command, only those specific file will extract which are mention there.

使用上面的命令,将仅提取其中提到的那些特定文件。

Recommended Articles:

推荐文章:

翻译自: https://www.includehelp.com/linux/zip-files-on-command-line.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值