有没有办法检查zip文件是否受密码保护?

时间:2019-05-07 20:42:23

标签: linux bash shell zip

我正在编写一个bash脚本,该脚本进行压缩(有无加密,取决于用户选择的内容),并使用zip解压缩文件。 我的问题是解压缩部分-当用户选择一个zip文件进行解压缩(通过选择zenity文件)时,有什么方法可以检查该文件是否受密码保护,以便向用户询问密码(或者是否为“ t,只需继续并解压缩文件)?

我真的还没有尝试任何东西,因为我一直想出任何主意或在堆栈和其他网站上找到解决方案。

1 个答案:

答案 0 :(得分:1)

if 7z l -slt file.zip | grep -q ZipCrypto; then
  echo "password protected / encrypted"
else
  echo "no password protection / not encrypted"
fi

请参阅:How to detect zip file encryption algorithm