为了账号安全,请及时绑定邮箱和手机立即绑定

shell脚本压缩解压?

shell脚本压缩解压?

慕桂英546537 2019-05-27 10:06:50
shell脚本压缩解压
查看完整描述

4 回答

?
慕哥9229398

TA贡献1877条经验 获得超6个赞

全部解压?7za 格式必须有他专用的解压程序 7z。文件名不要包含空格。
for i in *.7za
do
mkdir -p "x/$i"
7z x "$i" -o"x/$i"

done

7z解压自动使用多cpu核心。4个解压文件一个一个解压比4个同时解压效率高。

查看完整回答
反对 回复 2019-06-01
?
梦里花落0921

TA贡献1772条经验 获得超6个赞


filename=$1
dirname=`basename $filename .tar.gz`
if [ -z $1 ];then
echo Usage $0 filename
exit 1
fi

scp root@172.10.1.2:/opt/$file /opt
cd /opt
tar zxf $filename
pushd $dirname
find . -type f -name "*.zip" -exec unzip {} \;
find . -type f -name "*.rar" -exec unrar {} \;
popd

查看完整回答
反对 回复 2019-06-01
?
慕哥6287543

TA贡献1831条经验 获得超10个赞

#!/bin/bash
##for file zip and unzip
#date:2011/7/20

#input:current_filename
#use gunzip\bzip\tar commands to do this .
#two choices:pack||unpack

pack()
{
##use tar cmd to pack file
echo "Now will use tar to pack the file......"
echo "tar $CUR_FILE ......."
#sleep 1
tar -zcvf $CUR_FILE.tar.gz $CUR_FILE
if [ "$?" -eq "0" ];then
echo "pack file $CUR_FILE into tar.gz file ok~!"
else
echo "Error:Pack file into tar.gz failed~!"
exit 1
fi
}

unpack(){
##get file type
ftype=`file $CUR_FILE`
#echo file type
echo "Your file type is:###$ftype"
case "$ftype" in
"$CUR_FILE: Zip archive"*)
unzip $CUR_FILE
echo "unzip $CUR_FILE OK~!"
;;
"$CUR_FILE: gzip compressed"*)
gunzip $CUR_FILE
echo "gunzip $CUR_FILE OK~!"
;;
"$CUR_FILE: bzip2 compressed"*)
bunzip2 $CUR_FILE
echo "bunzip $CUR_FILE OK~!"
;;
*)
echo "File $CUR_FILE can not be uncompressed!!!"
exit 1
;;
esac

}

CUR_FILE="$1"
if [ -z $CUR_FILE];then
echo "Please input your filename!"
exit 1
else
echo "Your file name:$CUR_FILE"

##make target choice
echo "Which work you wanna do?"
select var in "pack" "unpack";do
break
done
echo "You selected $var file....."

case $var in
pack)
pack CUR_FILE
;;
unpack)
unpack CUR_FILE
;;
*)
echo "Usage:select option error!"
exit 1
esac
fi



查看完整回答
反对 回复 2019-06-01
  • 4 回答
  • 0 关注
  • 1080 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信