使用方法,将下述代码添加到根目录的.profile文件里,再运行source ~/.profile
即可。
- 默认参数为以5%恢复记录,15G分包压缩文件夹
- 压缩某个文件夹:
rr1 folder_name
- 批量压缩一个文件夹下的每个文件夹:
rra
- 如果想要压缩完之后删除源文件节省盒子空间,修改代码里面RAR参数,加个
-df
参数即可
function rr1 (){
echo "Compress the folder using rar with 5% recovery record";
if (($#==1)); then src="$1"; dst="$1";
elif (($#==2)); then src="$2"; dst="$1";
else echo "Error. Parameter must be 1 or 2.\n"; return 1; fi
if [[ $dst != *.rar ]]; then
if [[ $src == */ ]]; then src=${src%"/"}; fi
if [[ $dst == */ ]]; then dst=${dst%"/"}; fi
if [[ -d $dst && ${dst} != *${src} ]]; then
if [[ $dst == */ ]]; then dst=${dst%"/"}; fi
dst="${dst}/${src}"
fi
dst="${dst}.rar"
fi
if [ -f "${dst}" ]; then echo "File exists." return 1; fi
#tmpf=".rarcompresstmp"
#mkdir "${tmpf}"; cd "$src"; mv .* ../$tmpf/; cd ..;
#rar5 "$dst" "$src";
#cd "$src"; mv ../$tmpf/.* ./; cd ..; rm -rf "$tmpf";
if [[ -d $src ]]; then removehiddenfile "$src"; fi
echo "rar5 ${dst} ${src}"
rar a -m0 -rr5 -ma5 -v16106127360B "$dst" "$src";
}
function rra () {
if (($#==0)); then rrmusicalldst=".";
elif (($#==1)); then rrmusicalldst="$1";
else echo "Error. Parameter must be 1 or 0.\n"; return 1; fi
IFS=$'\n'
for i in `ls -1`; do
if [[ -d $i && "$i" != "*.rar" && "$i" != "*.zip" ]]; then
echo "rr1 \"${rrmusicalldst}\" \"$i\"";
rr1 "${rrmusicalldst}" "$i";
echo "################################################\n"
fi
done
unset IFS
}