Linux拆包+合包脚本
此脚本可以针对Linux环境下 zip
,tar.gz
,tar.bz2
压缩包进行分包+后续的合包
cat split.sh
#!/bin/bash
# 拆分包大小
Size=500M
FileName=$(ls -l ${1} |awk -F / '{print $NF}'|awk -F .tar.* '{print $1}'|awk -F .zip '{print $1}'|awk '{print $NF}')
Path=$(pwd)/split/${FileName}$(date +%F-%S)
Suffix=$(ls -l ${1}|awk -F / '{print $NF}'|awk '{print $NF}'|awk -F . '{print $NF}')
# 分包函数
splits(){
mkdir ${Path} -p
split -b ${Size} -d -a 5 ${1} ${1}. && \
mv ${1}.* ${Path}
}
# 合包函数
merge(){
if [[ ${Suffix} == "gz" ]];then
echo "cat ${FileName}.tar.* > ${FileName}.tar.${Suffix}" > ${Path}/${FileName}.sh
echo "rm -f ${FileName}.tar.${Suffix}.*" >> ${Path}/${FileName}.sh && \
echo "rm -f ${FileName}.sh">> ${Path}/${FileName}.sh && \
chmod +x ${Path}/${FileName}.sh
elif [[ ${Suffix} == "bz2" ]];then
echo "cat ${FileName}.tar.* > ${FileName}.tar.${Suffix}" > ${Path}/${FileName}.sh
echo "rm -f ${FileName}.tar.${Suffix}.*" >> ${Path}/${FileName}.sh && \
echo "rm -f ${FileName}.sh">> ${Path}/${FileName}.sh && \
chmod +x ${Path}/${FileName}.sh
elif [[ ${Suffix} == "zip" ]];then
echo "cat ${FileName}.zip* > ${FileName}.${Suffix}" > ${Path}/${FileName}.sh
echo "rm -f ${FileName}.zip.*" >> ${Path}/${FileName}.sh && \
echo "rm -f ${FileName}.sh">> ${Path}/${FileName}.sh && \
chmod +x ${Path}/${FileName}.sh
fi
}
splits ${1}
merge
执行后会在脚本所在当前路径生成 split
目录 咱们的分包后的数据会安装规定大小存放在 split
目录 如下图:
以 上面分包后的数据进行合包 举例:
进入分包后数据所在目录后 会有一个可执行脚本,执行这个脚本 进行合包 如下图: