您的位置:首页 > 运维架构 > Shell

Shell脚本一枚

2016-03-10 15:16 639 查看
脚本如下:

#!/bin/bash
dir=$1
dir1=""
for file in `find $dir -type f`
do
dir2=${file%/*}
name=${file%.*}
name1=${name%.*}
cd $dir2
gunzip $file
if [ -z "$dir1" -o "$dir1" != "$dir2" ];then
gzip -c "$name" > "$name1".gz
rm -rf "$name"
dir1="$dir2"
else
gzip -c "$name" >> "$name1".gz
rm -rf "$name"
fi
done


需要说明的是:

1. ${file%/*}:拿掉最后一个 / 及其右边的字符串

2. ${file%.*}:拿掉最后一个 .  及其右边的字符串

3. 第一个gzip是将file1压缩成foo.gz,第二个gzip是将file2添加到foo.gz中

    gzip -c file1 > foo.gz
    gzip -c file2 >> foo.gz

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: