如何在命令行中提取多个.gz日志文件

时间:2012-08-24 17:14:30

标签: command-line compression

我有多年的.gz文件中的日志文件。是否有一个命令可以用来将这些全部提取到当前目录中?我尝试解压缩* .gz但无法正常工作。还有其他建议吗?

1 个答案:

答案 0 :(得分:0)

shell脚本?

#!/bin/ksh

TEMPFILE=tempksh_$$.tmp                                          #create a file name
> $TEMPFILE                                                      #create a file w/ name

ls -l | grep '.*\.gz$' \                                         #make dynamic shell script
      | awk '{printf "unzip %s;\n", $9;}' \                      #with unzip cmd for each item
      >>  $TEMPFILE                                              #and write to TEMPFILE


chmod 755 $TEMPFILE                                              #give run permissions
./$TEMPFILE                                                      #and run it
rm -f $TEMPFILE                                                  #clean up

未经测试,但我认为你明白了......

实际上有点摆弄并且变得更简单......

 set -A ARR *.gz;
 for i in ${characters[@]}; do `unzip $i`; done;
 unset ARR;