bash repair_zip.sh /root/3.zip
Last active
May 19, 2020 04:43
-
-
Save Hootrix/1d5d96d95dc5238e170405c77d54f02f to your computer and use it in GitHub Desktop.
repair_zip.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
file=$1 | |
dir=`dirname $file` | |
# 检测文件存在 | |
if [ ! -f $file ];then | |
echo "404: file not found" | |
exit 1 | |
fi | |
# 检测zip命令 | |
if ! type "zip" > /dev/null; then | |
echo "500: command not found. Please execute install > apt-get/yum install zip" | |
exit 1 | |
fi | |
file_name=`echo $file | awk -F . '{print $1}'|awk -F '/' '{print $(NF)}'` # 截取文件名 | |
save_path=$dir/"$file_name"_repaired # 修复后提取存放路径 | |
echo -e "extract file: $file" | |
echo -e "processing... ... " | |
repaired_zip_package=$dir/"$file_name"_repaired.zip #修复后的压缩包路径 | |
zip -FF $file --out $repaired_zip_package && unzip $repaired_zip_package -d $save_path | |
sleep 1;unlink $repaired_zip_package | |
echo -e " \e[0;32msuccessful: $save_path\e[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment