怎么用shell写把一个.gz的压缩包解压

jdwq33 2012-08-02 04:52:18
今天我发现有我要解很多压缩包,于是我就想用shell编一个小程序,希望能通过这个程序来解决我的问题,
但是我不知道怎么来把那个压缩包的文件名给弄出来。大师们能否给一些建议啊???怎么可以写这个程序??
谢谢!!!
...全文
420 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Linux-Torvalds 2012-08-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

例如我想解压:ttt.gz 怎么写呢??find后面的那个点是什么意思呢?还有那个大括号{}是什么意思???
[/Quote]那就直接写了。
tar zxvf ttt.tar.gz

find后面那个点好表示当前目录。大括号指的是find找到的文件。
jdwq33 2012-08-03
  • 打赏
  • 举报
回复
例如我想解压:ttt.gz 怎么写呢??find后面的那个点是什么意思呢?还有那个大括号{}是什么意思???
夏天__ 2012-08-03
  • 打赏
  • 举报
回复
find . -name "*.gz" -exec tar zxvf {} \;
find . -name "*.bz" -exec tar jxvf {} \;
jdwq33 2012-08-03
  • 打赏
  • 举报
回复
呵呵 谢谢大师
__Cheny 2012-08-03
  • 打赏
  • 举报
回复
改过如下:

#!/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
jdwq33 2012-08-03
  • 打赏
  • 举报
回复
真不好意思,需要辨别然后再解压。呵呵 麻烦了啊 谢谢
__Cheny 2012-08-03
  • 打赏
  • 举报
回复
#!/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
已经成功测试
wyjq395 2012-08-03
  • 打赏
  • 举报
回复
楼主先试一下别人的答案啊
Linux-Torvalds 2012-08-02
  • 打赏
  • 举报
回复
find . -name "*.gz" -exec tar zxvf {} \;

23,116

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧