用Shell命令批量压缩指定目录下指定目录到目标目录中
来源:互联网 发布:手机淘宝评价怎么删 编辑:程序博客网 时间:2024/05/16 14:29
#!/bin/bash
function usage(){
echo ""
echo "introduction: tar of source dir start with pattern files or dirs to target dir"
echo "patch_tar_pattern: usage: bash patch_tar_pattern -s [source dir] -t [target dir] -p [pattern]"
exit 1
}
while getopts "s:t:p:" arg #选项后面的冒号表示该选项需要参数
do
case $arg in
s)
source="$OPTARG" #参数存在$OPTARG中
;;
t)
target="$OPTARG"
;;
p)
pattern="$OPTARG"
;;
?) #当有不认识的选项的时候arg为?
echo "unkonw argument"
usage
;;
esac
done
if [ -z $source ]
then
usage
fi
if [ -z $target ]
then
usage
fi
if [ -z $pattern ]
then
usage
fi
if test ! -d $source
then
echo "$source not exists!"
exit 1
fi
if test ! -d $target
then
echo "$target not exists!"
echo "mkdir -p -m 777 $target"
mkdir -p -m 777 $target || exit 1
fi
cd $source
dir_list=`ls | grep "^$pattern"`
for dir in $dir_list
do
if test -d "$source/$dir"
then
#tar -zcvf "$target/${dir}.tar.gz" "$dir"
echo "tar"
if test -f "$target/${dir}.tar.gz"
then
echo "tar -zcvf $target/${dir}.tar.gz $dir"
echo "$source/$dir" >> "$target/tar_success.log"
else
echo "$source/$dir" >> "$target/tar_error.log"
fi
fi
done
function usage(){
echo ""
echo "introduction: tar of source dir start with pattern files or dirs to target dir"
echo "patch_tar_pattern: usage: bash patch_tar_pattern -s [source dir] -t [target dir] -p [pattern]"
exit 1
}
while getopts "s:t:p:" arg #选项后面的冒号表示该选项需要参数
do
case $arg in
s)
source="$OPTARG" #参数存在$OPTARG中
;;
t)
target="$OPTARG"
;;
p)
pattern="$OPTARG"
;;
?) #当有不认识的选项的时候arg为?
echo "unkonw argument"
usage
;;
esac
done
if [ -z $source ]
then
usage
fi
if [ -z $target ]
then
usage
fi
if [ -z $pattern ]
then
usage
fi
if test ! -d $source
then
echo "$source not exists!"
exit 1
fi
if test ! -d $target
then
echo "$target not exists!"
echo "mkdir -p -m 777 $target"
mkdir -p -m 777 $target || exit 1
fi
cd $source
dir_list=`ls | grep "^$pattern"`
for dir in $dir_list
do
if test -d "$source/$dir"
then
#tar -zcvf "$target/${dir}.tar.gz" "$dir"
echo "tar"
if test -f "$target/${dir}.tar.gz"
then
echo "tar -zcvf $target/${dir}.tar.gz $dir"
echo "$source/$dir" >> "$target/tar_success.log"
else
echo "$source/$dir" >> "$target/tar_error.log"
fi
fi
done
0 0
- 用Shell命令批量压缩指定目录下指定目录到目标目录中
- 用Shell命令批量解压一个目录下分卷的压缩包到指定目录
- linux命令复制指定文件或者指定目录下的全部文件到另一个目录中
- shell 批量压缩指定目录及子目录内图片
- shell 批量压缩指定目录及子目录内图片
- shell批量删除指定目录下的文件
- shell在指定目录下批量执行sql脚本
- 用rar命令行 添加指定文件到压缩包的指定目录中
- 用Dos命令把目录下所有文件保存到一个指定文件中
- tar 压缩文件夹到指定的目录
- centos 解压压缩包到指定目录
- linux打包和解压缩到指定目录
- Linux命令 tar压缩排除指定目录
- Linux shell批量删除指定目录下的所有目录的编程思路
- 目录下指定文件的批量清理
- C#批量附加指定目录下的所有数据库文件到数据库中
- shell 拷贝文件到指定用户目录
- linux下tar命令解压到指定的目录
- Android studio 修改工程的包名
- OpenCV基础篇之图像的DFT频域变换
- 文件和目录的删除
- Hibernate懒加载解析
- File类的基本用法,看完这个程序你就会了
- 用Shell命令批量压缩指定目录下指定目录到目标目录中
- How to Marshal a C++ Class
- 分层
- Toolbar滑动效果实现总结
- javaweb 过滤器和监听器总结
- Android开源框架——图表MPAndroidChart
- 数列[HNOI2013][Codevs2089]
- mouseenter()和mouseleave()一对绝佳搭档
- text data bss heap stack