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.
就像我们之前讨论的那样,我们可以使用TAR或Gzip / bzip2进行压缩或解压缩,另一种流行的替代方法是ZIP 。
示例1:压缩 (Example 1: Zipping)
Let's try with archiving some files and compressing them.
让我们尝试将一些文件存档并压缩它们。
![Zip in Linux](https://i-blog.csdnimg.cn/blog_migrate/647a0ad9f29deb3568f1f02868be1d29.png)
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](https://i-blog.csdnimg.cn/blog_migrate/3b342d88173c6f46ccbe2adcb7f833b6.png)
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](https://www.includehelp.com/linux/images/zip-3.jpg)
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