日期:2014-05-16  浏览次数:20667 次

怎么用shell写把一个.gz的压缩包解压
今天我发现有我要解很多压缩包,于是我就想用shell编一个小程序,希望能通过这个程序来解决我的问题,
但是我不知道怎么来把那个压缩包的文件名给弄出来。大师们能否给一些建议啊???怎么可以写这个程序??
谢谢!!!

------解决方案--------------------
find . -name "*.gz" -exec tar zxvf {} \;
------解决方案--------------------
find . -name "*.gz" -exec tar zxvf {} \;
find . -name "*.bz" -exec tar jxvf {} \;
------解决方案--------------------
探讨

例如我想解压:ttt.gz 怎么写呢??find后面的那个点是什么意思呢?还有那个大括号{}是什么意思???

------解决方案--------------------
楼主先试一下别人的答案啊
------解决方案--------------------
#!/bin/bash
# unzip the files with tar shell script

## define the directory of gz-packet and target. 
GZDIR=$1
TARDIR=$2

## get the name of gz-packet
GZLIST=`ls ${GZDIR}`

## 
for i in $GZLIST
do
tar zxvf ${GZDIR}/$i -C ${TARDIR}
done
echo DONE!
exit

这个脚本的用法是 比如/root/test 下有很多.gz的压缩包。(条件是全部都是.gz的压缩包。如果需要在目录下辨别是否是gz再解压的话,请告知,我再写。)
/root/target这个目录是你想将这些压缩包解压到的目录。
执行的时候这样 ./tartest.sh /root/test /root/target 
已经成功测试
------解决方案--------------------
改过如下:

#!/bin/bash
# file name : tartest.sh
# unzip the files with tar shell script

## define the directory of gz-packet and target. 
GZDIR=$1
TARDIR=$2

## get the name of gz-packet
GZLIST=`ls ${GZDIR}`
NEWGZLIST=()

## get the .gz filename
NEWGZLIST=`find ${GZDIR} -name "*.gz"`

## unzip the gz-packet to the target directory
for i in ${NEWGZLIST}
do
tar zxvf $i -C ${TARDIR}
done
echo DONE!
exit