跳过在Ubuntu中解压7z时的错误密码。

huangapple go评论90阅读模式
英文:

Skip wrong password for 7z extraction Ubuntu

问题

Sure, here's the translated content:

任务是从存储在“IN”目录中的多个受密码保护的存档中提取文件,使用7zip包,密码存储在名为“PASS”的列表中。我遇到了一个问题:当密码错误时,7zip会创建空文件夹和文件。是否有方法可以跳过错误的密码并继续下一次迭代?
这是我的bash脚本:

FILES=./IN/*
PASS=('1' '2' '3')
for f in $FILES
do
 for psd in "${PASS[@]}"
  do
   if 7z x -y -p"$psd" -o./OUT $f | grep 'ERROR'; then
    break
   fi
  done
done

请注意,我已经修复了脚本中的引号问题,并将${PASS[@]}括在双引号中以正确地处理密码列表。

英文:

The task is to extract files from multiple password-protected archives stored in “IN” directory with 7zip package, passwords stored in list “PASS”. I have a problem: when the password is wrong 7zip creates empty folders and files. Are there any ways to skip wrong password and go to next iteration?
Here’s my bash script

FILES=./IN/*
PASS=(‘1’ ‘2’ ‘3’)
for f in $FILES
do
 for psd in $(PASS[@])
  do
   if 7z x -y -p”$psd” -o./OUT $f | grep ‘ERROR’; then
    break
   fi
  done
done

答案1

得分: 0

以下是已翻译的内容:

这里有一个建议:在尝试提取之前,使用 7zz t(测试归档完整性)来确定您列表中的给定密码是否有效。

示例:

#! /bin/sh

WORKDIR='path/to/your/work/dir'

PW='1 2 3'

for File in "$WORKDIR"/*.zip
do  
    test -r "$File"   ||   continue
    for Password in $PW
    do  
        7zz t -p"$Password" "$File" >/dev/null 2>&1 \
        &&   { 7zz x -p"$Password" "$File";   break; }
    done   ||   echo "warning: could not extract file \"$File\" (no valid password found)"
done

备注:

  • 如果您已安装了“7zip”软件包,则归档命令名称为7zz
  • 如果您已安装了“p7zip-full”软件包(7-Zip的Unix CLI端口),则归档命令名称为7z

在Linux Debian 11上进行了测试。

希望这有所帮助。

英文:

Here's a suggestion : use 7zz t (test archive integrity) to determine if a given password in your list is valid before attempting extraction.

Example:

#! /bin/sh
                                                                                                                                                                                               
WORKDIR='path/to/your/work/dir'

PW='1 2 3'

for File in "$WORKDIR"/*.zip
do  test -r "$File"   ||   continue
    for Password in $PW
    do  7zz t -p"$Password" "$File" >/dev/null 2>&1 \
        &&   { 7zz x -p"$Password" "$File";   break; }
    done   ||   echo "warning: could not extract file \"$File\" (no valid password found)"
done
Note:
  • if you've installed package "7zip", the archiver command name is 7zz.

  • if you've installed package "p7zip-full" (the Unix CLI port of 7-Zip), the archiver command name is 7z.


Tested on Linux Debian 11.

Hope that helps.

huangapple
  • 本文由 发表于 2023年7月13日 15:50:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76677070.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定