

Linux unzip 命令解压多个ZIP文件
source link: https://www.myfreax.com/linux-unzip-command-to-unzip-multiple-zip-files/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux unzip 命令解压多个ZIP文件
在本教程中,我们将说明如何在Linux使用unzip命令解压多个zip文件

Linux unzip 命令解压多个ZIP文件
ZIP是最广泛使用的存档文件格式,支持无损数据压缩。ZIP文件是一个数据容器,其中包含一个或多个压缩文件或目录。
在本教程中,我们将说明如何在Linux使用unzip命令解压多个zip文件。
unzip是一个命令行程序,可帮助您列出,测试和解压缩ZIP存档文件。unzip
在大多数Linux发行版中均未默认安装,但是您可以使用发行版的软件包管理器安装它。
安装 unzip
要检查您的系统上是否安装unzip,请运行命令unzip --version
,命令将会打印unzip的版本号。
如果您的系统上未安装unzip,终端将会提示你bash: command not found: unzip。可以使用发行版的软件包管理器进行安装。
如果你的计算机运行的是基于Debian的Linux发行版,例如Ubuntu,Linux mint,可以运行sudo apt update && sudo apt install unzip
安装unzip。
如果你的计算机运行的是基于Redhat的Linux发行版,例如Fedora,CentOS。可以运行sudo yum install unzip
安装unzip。
sudo apt install unzip
sudo yum install unzip
解压 ZIP文件
最简单的形式是不带任何选项与参数运行unzip命令,unzip
命令会将所有文件从指定的ZIP存档文件提取到当前目录。
要将ZIP存档文件解压到指定目录中,用户需要对该目录具有写权限。
ZIP文件不支持Linux权限信息,提取的文件并不保留原始权限的信息,解压的文件归运行unzip命令的用户所有。
例如,假设您下载安装Wordpress的ZIP文件。要将文件解压到当前目录,请运行命令unzip latest.zip
。
unzip latest.zip
unzip 命令解压多个ZIP文件
如果您的当前工作目录中有多个ZIP文件,则可以仅使用通配符匹配所有zip文件进行解压。
在使用*通配符时,建议使用单引号将通配符引起来,避免shell的解释。如果您忘记使用单引号,则shell会扩展通配符,并且会出现错误。
unzip '*.zip'
禁用 unzip标准输出
默认情况下,unzip
命令会打印解压的文件的名称以及提取完成后的摘要。可以使用-q
选项禁止打印这些消息。
unzip -q filename.zip
unzip 指定解压目录
要将ZIP文件解压到指定的目录,请使用-d
选项。-d
选项的参数可以是目录的相对路径或者绝对路径。
例如,要将WordPress存档latest.zip
解压到/var/www/
目录,请运行命令sudo unzip latest.zip -d /var/www
。
在上面的命令中,我们使用sudo
,因为在大多数情况下,当前登录的用户没有对/var/www
目录的写入权限。
使用sudo解压ZIP文件时,提取的文件和目录将归root用户所有。
sudo unzip latest.zip -d /var/www
unzip 解压加密zip文件
要解压受密码保护的文件,请使用-P
选项,后跟密码。例如命令unzip -P PasswOrd filename.zip
,PasswOrd
是密码。
unzip -P PasswOrd filename.zip
unzip 命令排除文件
从zip文件解压时并不是所有文件都是你需要的,你可能需要排除指定的文件。unzip命令的-x
选项,允许你指定要排除的文件。
-x
选项指定路径是zip内部文件显示的路径,也就是unzip -l
命令打印的文件或者目录的路径。
例如命令unzip filename.zip -x ".git/"
从ZIP存档中排除.git
目录并解压其它文件和目录。
unzip filename.zip -x "*.git/*"
unzip 命令覆盖文件
假设您已经解压了Zip文件,然后再次运行相同的命令。
默认情况下,unzip
会询问您是否要仅覆盖当前文件,覆盖所有文件,跳过提取当前文件,跳过提取所有文件还是重命名当前文件。
如果需要在强制覆盖存在的文件,请使用-o
选项。建议谨慎使用此选项。文件将被覆盖,并且如果您对文件进行的更改都将会丢失。
unzip -o filename.zip
Archive: latest.zip
replace wordpress/xmlrpc.php? [y]es, [n]o, [A]ll, [N]one, [r]ename:
unzip 命令仅提取不存在的文件
假设您已经解压了一个ZIP文件,并且对某些文件进行了更改,但不小心删除了几个文件。您要保留更改并从ZIP存档中恢复已删除的文件。
在这种情况下,您可以使用-n
选项,强制unzip
跳过对已存在文件的提取。
unzip -n filename.zip
unzip 命令列出zip文件
要列出ZIP文件的内容,请使用-l
选项,后跟zip文件名称。例如命令unzip -l latest.zip
将会列出WordPress安装文件。
unzip -l latest.zip
Archive: latest.zip
Length Date Time Name
--------- ---------- ----- ----
0 2018-08-02 22:39 wordpress/
3065 2016-08-31 18:31 wordpress/xmlrpc.php
364 2015-12-19 12:20 wordpress/wp-blog-header.php
7415 2018-03-18 17:13 wordpress/readme.html
...
...
21323 2018-03-09 01:15 wordpress/wp-admin/themes.php
8353 2017-09-10 18:20 wordpress/wp-admin/options-reading.php
4620 2017-10-24 00:12 wordpress/wp-trackback.php
1889 2018-05-03 00:11 wordpress/wp-comments-post.php
--------- -------
27271400 1648 files
我们已经讨论了如何在Linux终端运行unzip命令解压zip文件。要在Linux创建ZIP存档文件,您需要使用zip命令。
Recommend
-
12
How to Install Zip and Unzip in Linux? Related Articles Improve Article How to Install Zip and Unzip in Linux?Difficulty Level :
-
58
How to zip and unzip files from Terminal in Linux 401 views 2 months ago Ubuntu Zip is the most common fe...
-
12
How to Zip and Unzip Files in PHP Monty Shokeen Oct 19, 2018 ...
-
11
压缩zip func Zip(dest string, paths ...string) error { zfile, err := os.Create(dest) if err != nil { return err } defer zfile.Close() zipWriter := zip.NewWriter(zfile) defer zipWriter.Clo...
-
10
unzip Linux unzip命令解压加密zip文件 ZIP是最广泛使用的存档文件格式,支持无损数据压缩 ...
-
14
unzip Linux unzip命令解压zip文件 ZIP是最广泛使用的存档文件格式,支持无损数据压缩 ...
-
8
unzip Linux unzip 命令指定解压目录 我们将说明如何在Linux使用unzip 命令指定解压目录 ...
-
9
unzip Linux unzip 命令合并解压分卷文件 Zip是使用最广泛的存档文件格式,它支持无损数据压缩
-
7
Java把文件压缩成.zip压缩包和解压.zip压缩包 精选 原创 共饮一杯无 2022-12-30 20:56...
-
7
背景&需求一个无层级的极简压缩,主要是用于应用的数据库以及SP导入导出使用,不希望引入三方插件库。object ZipManager { fun zip(files: Array<File>, zipFile: File) { ZipOutputStream(zipFile.outputStream...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK