- #!/bin/bash
- direc="/usr/my"
- targetpath="/usr/tmp"
- OLDIFS=$IFS
- IFS=:
- for path in $( find $direc -type d -printf "%p$IFS")
- do
- mkdir -p "$targetpath/${path:${#direc}+1}"
- for file in $path/*
- do
- if [ -f $file ]; then
- zip -j "$targetpath/${path:${#direc}+1}/${file:${#path}+1}.zip" "$file"
- fi
- done
- done
- IFS=$OLDIFS
- #该片段来自于http://www.codesnippet.cn/detail/240420133009.html
来源: http://www.codesnippet.cn/detail/240420133009.html